Cookie summary in PHP5 (1) I. cookie configuration and application settings cookieboolsetcookie (stringname [, stringvalue [, intexpire [, stringpath [, stringdomain [, boolsecure]);? Delete the Cookie summary in cookieboolsetcooki PHP5 (1)
1. cookie configuration and application
Set cookie
BoolSetcookie(String name [, string value [, int expire [, string path [, string domain [, bool secure]);
?
Delete cookie
Bool setcookie (name ,"");
?
Parameter description example
Name |
Cookie name. |
Use$ _ COOKIE ['cookiename']Call the cookie named cookiename. |
Value |
Cookie value. This value is stored on the client and cannot be used to save sensitive data. |
Assume thatNameIs 'cookiename', you can use$ _ COOKIE ['cookiename']Obtain the value. |
Expire |
The time when the Cookie expires. This is a Unix timestamp, that is, the number of seconds from the Unix epoch. In other words, it is usually usedTime ()The function plus the number of seconds to set the cookie expiration time. Or useMktime (). |
Time () + 60*60*24*30The cookie is set to expire after 30 days. If not set, the cookie will expire after the session ends (usually closed by the browser. |
Path |
Valid Cookie path on the server. |
If this parameter is set'/'Then, the cookie isDomainIs valid. if it is set'/Foo /'The cookie isDomainUnder/Foo/Directory and its subdirectories are valid, such/Foo/bar/. The default value is the current directory of the cookie. |
Domain |
The valid domain name of the cookie. |
This parameter should be set'.Example.com'. Although.Not required, but it will be compatible with more browsers. If this parameter is setWww.example.comInWwwValid in the subdomain. For details, see tail matching in the Cookie specification. |
Secure |
Indicates whether the cookie is transmitted only through a secure HTTPS connection. When setTRUEThe cookie is only set in secure connections. The default value isFALSE. |
0Or1 |
?
Like other headers, cookies must be sent before any other output of the script (this is a protocol restriction ). This requires that the call of this function be placed before any output, includingAndLabel and any space. IfSetcookie ()If there is any output before, this function will fail and returnFALSE. IfSetcookie ()If the function runs successfullyTRUE. This does not indicate whether the user has accepted the cookie.