Home >Backend Development >PHP Problem >How to set cookies in php
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 100db36a723c770d327fc0aef2ce13b1 and 93f0f5c25f18dab9d176bd4f6de5d30e 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!