Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
Or some websites (such as the NetEase community) can automatically record the information you have logged on.
Is the Cookie.
2. Pass variables between pages. The browser does not save any variable information on the current page.
The page is closed, and any variable information on the page disappears. If you have a variable on a page
A = 5. To pass this variable to another page, you can use http: // url? A = 5 transmission changes
Or insert a form in the webpage and insert an implicit field (input hidden
Volume is saved as a Cookie, and then the variable value is obtained by reading the Cookie on the next page.
Note: The Cookie must be sent before other headers; otherwise, an error occurs!
The following example records the number of visits of a visitor:
$ HTTP_COOKIE_VARS ["VisitTimes"]? ($ VisitTimes ++) :( $ VisitTimes = 1 );
Setcookie ("VisitTimes", $ VisitTimes, time () + 31536000 );
Echo "<B> Welcome <font color =" # FF0000 ">". $ VisitTimes.
"</Font> Visit my homepage </B> <br> ";
The running result is shown at the top of this page (refresh to see if the number of visits has changed ).
PHP's Cookie function is:
Int setcookie (string name, string value, int expire, string path,
String domain, int secure );
Cookie validity period, standard Unix timestamp
String path, domain
Cookie path and domain name
Whether the cookie is transmitted in secure http mode
Among them, except the string name parameter is required, other parameters are optional. Int expire is
The second difference between on January 1, January 1, 1970 and a certain time. Its default value is 0, that is, browsing
When the cookie is disabled, it is automatically deleted. In the preceding example, the validity period is one year (365*24*3600 = 31536000 ).
Again, the cookie must be sent before other headers on the webpage. Otherwise, an error occurs !!
There are two methods to read the Cookie value after it is set:
Directly use the cookie name as the variable name, that is, $ name.
Use $ HTTP_COOKIE_VARS ["name"].
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to email@example.com. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.