Wednesday, 25 February 2015

How to store array in Cookie and retrieve array from cookie

How to store array in Cookie and retrieve array from cookie

How to store array in Cookie
We need to json_encode the array then save the data with setcookie function.
$arrayData=array(
    'web technology experts',
    'web technology experts Notes',
    'web technology experts Notes  php technology'    
);
setcookie('cookieData', json_encode($arrayData));


How to Retrieve array in Cookie
As we have encoded the array above, So we need to json_decode the array before use.
$arrayData = json_decode($_COOKIE['cookieData']);


How to set time in cookies
$arrayData=array(
    'web technology experts',
    'web technology experts Notes',
    'web technology experts Notes  php technology'    
);
setcookie('cookieData', json_encode($arrayData), time()+3600);// set time for 1 hour [1 hour=3600 seconds]


 


How to delete Content of File in windows and unix?


Sometimes there are need to empty a file without opening the file. We can do the same with following two methods.

Method 1.
Delete the file and re-create the file with same name and extension.


Method 2.
Follow the simple steps.
1. Press window+R
2. Type the cmd and press enter key.
3. Now you are not window command prompt area.
4. Go to the same folder where file exits to delete the content.
5. Type the following command (replace the demo.txt with your file name)
 copy /y nul demo.txt
6. Now check its empty.



Question: How to delete the content of file in Unix?
Following are three different way, choose which suites to you.
cp /dev/null filename.txt
touch filename.txt
truncate -s 0 filename.txt