Setcookie parameter description

Definitions and Usage

The setcookie() function sends an HTTP cookie to the client.

A cookie is a variable sent by the server to the browser. Cookies are usually small text files embedded by the server into the user’s computer. This cookie is sent whenever the computer requests a page through the browser.

The name of the cookie specifies a variable with the same name. For example, if a cookie is sent with the name” name”, a variable named $user is automatically created that contains the value of the cookie.

The cookie must be assigned before any other output is sent.

This function returns true if successful, false otherwise.

$_COOKIE[‘user’] $_COOKIE[‘user’] $_COOKIE[‘user’]

$_COOKIE[‘user’]; $_COOKIE[‘user’]; $_COOKIE[‘user’];

Expire is optional. This parameter is used to set the duration of cookie variables. Note that the UNIX timestamp we set minus the current UNIX timestamp is the duration of cookie variables. UNIX timestamp: The number of seconds elapsed since January 1, 1970 (midnight UTC/GMT). Normally we can get the current UNIX timestamp with the time() function, plus the time we want to save (in seconds). For example, Setcookie (” user “, “PHP”,time()+3600), so we can save the user cookie variable for 3600 seconds. In addition, we can delete the cookie variable by setting the timestamp less than the current timestamp, such as setcookie(” user “, “PHP”,time()-1).

Fourth: If path is set to “/”, this parameter is valid for the entire domain. For example, setcookie(” user “, “PHP”,time()+3600, “/”), so that any directory in our domain, any text can call the value of the COOKIE variable through COOKIE[‘ user ‘]. Setcookie (” user “, “PHP,time()+3600,” /test1 “); Only the test1 directory can call the value of the cookie variable with _COOKIE[‘user’]. If path is set to /test, only the /test directory and subdirectories under the domain are valid. For example, the domain has two directories: Test1,test2, we set setcookie(” user “, “PHP,time()+3600,” /test1 “), then only test1 directory can call the value of the COOKIE variable [‘ user ‘]. Setcookie (” user “, “PHP,time()+3600,” /test1 “); _COOKIE[‘user’] can only be called from test1.

If domain is set to googlephp.cn, then all subdomains under Googlephp.cn are valid. Assume that googlephp.cn has two subdomains, php.googlephp.cn, css.googlephp.cn, If we set setcookie(” user “, “PHP”,time()+3600, “/”, “php.googlephp.cn”), the value of the cookie variable user can be obtained only in the php.googlephp.cn subdomain. Here’s another example: Setcookie (” user “, “PHP”,time()+3600, “/test”, “php.googlephp.cn”), the value of the cookie variable user can be obtained only from the test directory in the php.googlephp.cn subdomain.

The value is 0 or 1. If the value is 1, the cookie is valid only on HTTPS connections. The default value is 0, indicating that cookei is valid on both HTTP and HTTPS connections.