The syntax for setting cookies in PHP is "setcookie("user",$user,time() 3600);", where "user" represents the user name and "$user" represents the value of the variable.
PHP Setting and Reading Cookie
1. Setting Cookie
setcookie("user",$user,time()+3600); // user 为用户名,$user 为变量的值
Recommended: " PHP Tutorial》
Second, read Cookie
echo @$_COOKIE["user"];
Related introduction:
setcookie — Send Cookie
Instructions
setcookie ( string $name [, string $value = "" [, int $expire = 0 [, string $path = "" [, string $domain = "" [, bool $secure = false [, bool $httponly = false ]]]]]] ) : bool
setcookie() defines the cookie, which will be sent to the client together with the remaining HTTP headers. Like other HTTP headers, the cookie must be sent before the script can produce any output (due to protocol limitations). Please call this function before producing any output (including and
or spaces).Once the cookie is set, you can use $_COOKIE to read it the next time you open the page. Cookie values also exist in $_REQUEST.
The above is the detailed content of How to set cookies in php. For more information, please follow other related articles on the PHP Chinese website!