PHP Advanced: Flexible use of cookie_php tutorials

Source: Internet
Author: User
Cookies are powerful and convenient features that provide a range of full variables, and look at the syntax of cookies:
Setcookie (Cookievalue,value,time,path,domain);
Cookievalue is a set cookie variable, value is a variable that sets a value to a cookie, time is the duration of the cookie variable, and path is the cookie-action domain;
It is important to note that setting cookies within a PHP program must not be set after the HTML tag.
Let's look at an example:
Setcookie ("Cookietime", "2001-5-2", Time () +3600, "/", "test.php");
This cookie is set to give the date "2001-5-2" a cookie variable $cookietime, with a time of 3,600 seconds, and this variable takes effect in/test.php.
At this time add echo $cookietime in the test.php; It will show up in 2001-5-2.
If you leave the time in the cookie blank, the cookie expires when you close the browser.
A special place for a cookie is that the value of the cookie setting is not executed immediately until the second reference is executed, so what is the value of the cookie that is referenced for the first time?
is the value set by the cookie last time, it's a bit hard to understand, it's okay, for example, it all comes down to:
Setcookie ("Cookietime", Time,time () +3600, "/", "test.php");
At the first reference, there is no value in the $cookietime, and the second reference finds that time in the $cookietime is displayed, and it is fixed at 2001:
Setcookie ("Cookietime", 2001,time () +3600, "/", "test.php");
Once again, the first reference $cookietime the value of time, the second reference $cookietime value is 2001; What is the function of this feature of cookies? A clever reader may already know its usage, which is used for notification and alarm functions;
Looking at an example of the use of cookies, the function of the program is that when the user next visit the site, all the new information that the user has not seen is added a (new), the use of cookies to complete this function is simple, at least in my opinion, there is no other way than to use Cookie to complete this function is much simpler.
Storing information naturally takes a time value, as long as the database has stored the time value associated with each piece of information plus a cookie to complete this seemingly good feature:
test.php:
$time =date (' y-m-d h:i:s ');
Setcookie ("Cookietime", $time, Time () +3600000, "/", "test.php");
......
......
Fetch time value from database

http://www.bkjia.com/PHPjc/445177.html www.bkjia.com true http://www.bkjia.com/PHPjc/445177.html techarticle A cookie is a powerful and convenient feature that provides a range of full variables to look at the syntax of a cookie: Setcookie (cookievalue,value,time,path,domain); Cookievalue is set Coo ...

  • Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.