Cookies are a powerful and handy feature that provides a range of whole variables to look at the syntax of cookies:
Setcookie (Cookievalue,value,time,path,domain);
Cookievalue is a cookie variable that is set, value is a variable that sets a value to a cookie, time is the function of the cookie variable, and path is the way of the cookie, domain is the field of the cookie function;
It is important to note that when you set cookies inside a PHP program, you must not set them behind the HTML tag.
Let's look at an example:
Setcookie ("Cookietime", "2001-5-2", Time () +3600, "/", "test.php");
This cookie setting means giving the date "2001-5-2" a cookie variable $cookietime, which takes 3,600 seconds, and this variable is in effect in/test.php.
Then add echo $cookietime to the test.php; will show the 2001-5-2.
If the time in the cookie is empty, the cookie is invalidated when the browser is closed.
Cookie has a special place is that the value of the cookie set is not immediately executed, until the second reference will be executed, then the first reference to the cookie value?
It's the last time the cookie was set, and it's a little hard to understand here, and for example it's all clear:
Setcookie ("Cookietime", Time,time () +3600, "/", "test.php");
When the first reference is not a value in the $cookietime, the second reference finds that the time in the $cookietime appears, and repairs the time to 2001:
Setcookie ("Cookietime", 2001,time () +3600, "/", "test.php");
Once again, when the first reference $cookietime value is time, the second reference $cookietime value is only 2001; What does this feature of cookies do? Smart readers may already know their usage, which is used for notification and alarm functions;
Look at an example of using the cookie feature, the function of the program here is that when the user browses the Web site next time, all the new information that the user has not seen is added to it, and the cookie is the easiest way to do it, at least not in my opinion. Cookies to accomplish this function is simpler.
Storing information naturally requires a time value, as long as the database has the time value associated with each piece of information, plus a cookie, to do what looks like a good feature:
test.php:
$time =date (' y-m-d h:i:s ');
Setcookie ("Cookietime", $time, Time () +3600000, "/", "test.php");
......
......
Fetching time values from the database
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.