Thursday, 26 November 2015

28_php_set_cookie_variable_part1

Create Cookies


Cookies is piece of data if you liked or file that store with specific information and unique to you and the website you are viewing. So if you view on your browser a website set specific cookies when you access that website depending on the expression time of cookie that piece of data will relate from your computer to the website. So this way website can store the data about user or about specific preferences on that website and it can store on your computer for later access. So let’s understand how to work with the cookies. Basically cookie store the data for later access.


Use setcookie() function contain three argument 1st :- Cookie name, 2nd :- Value of that cookie variable and 3rd:- Time for cookie valid for (By Default in second).



Here in the first image you can see that we need to specify the current + expire time for the cookie variable. In page viewcookie.php page echo cookie variable value. Now run the index.php and within 30 second run the page viewcookie.php page. It will display the output”Harshida”. If you try to viewcookie.php page after 30 second nothing is going to be display on that page.


Remember one thing is cookie is store on the USER COMPUTER So it not useful to use for the operation like sensitive data shopping cart and etc.



No comments:

Post a Comment