Setcookie function

bool setcookie ( string $name [, string $value = "" [, int $expire = 0 [, string $path = "" [, string $domain = "" [, bool $secure = false [, bool $httponly = false ]]]]]] )Copy the code
parameter annotations
name The name of the Cookie.
value The Cookie value. For example, if name is ‘cookiename’, $_COOKIE[‘cookiename’] can be used to obtain its value.
expire Expiration time, Unix timestamp.
path Cookie valid path. If this parameter is set to ‘/’, domain is valid for the entire domain name. If the parameter is set to /user/, this parameter applies only to the domain parameter Value /user/ directory and its subdirectories. The default value is the current directory of the access address to which this function belongs
domain Valid domain name of the Cookie. The valid domain name is the specified domain name and all its subdomains. If w1.example.com is set, w1.example.com and all of its subdomains take effect. If example.com is set, that takes effect is Example.com and all of its subdomains. Older browsers are still in use obsoleteRFC 2109, requires a leading point (.) To match all subdomains.
secure Whether to transmit only over an HTTPS connection. The default value is false.
httponly Whether to access only through HTTP, set to false to deny access to scripting languages such as JavaScript. The default value is false.

RFC 6265 reference standard for each parameter of setcookie()

The above is the official PHP documentation setcookie function content, made some changes.

Setcookie Domain code example

The “operable” in the code sample means that it can be obtained using $_COOKIE, and can be modified using setcookie (deleting is also a modification; setting the expire parameter to a timestamp less than the current time is equivalent to deleting, such as time()-86400)

// example.com, *.example.com operable setcookie(' blog_URL ', 'back three rows -housanpai.com', time()+86400, '/', 'example.com'); // w1.example.com, *.w1.example.com operable setcookie(' blog_URL ', 'back three rows -housanpai.com', time()+86400, '/', 'w1.example.com');Copy the code