& Amp; lt ;? Phpif (! Isset ($ _ COOKIE ['visited']) {// if the cookie does not exist, create a new setcookie (& quot; visited & quot;, & quot; www. phpddt. co
The session management mechanism only includes the cookie and session mechanisms. let's talk about the cookie and session applications!
(1) Cookie is a small text file used to save user names, passwords, and personalized settings. when a user accesses a website,
A file like this will be generated and saved on the user's computer. Generally, the browser will store Cookies in their temporary files!
Note that Cookies do not store confidential information, such as bank accounts, in consideration of security issues!
The setcookie () function is used in php to generate a cookie. See the following simple example:
It can be seen that the setcookie () function mainly receives six parameters:
Name: cookie name (required)
Value: The cookie value.
Expires: cookie Expiration Time (required)
Path: "/" indicates that all arrays in this field can be accessed and read.
Domain: valid cookie domain name
Secure: bool value. if it is true, it indicates that the cookie can be sent to the client only when the ssl encrypted connection is established.
Note that no script can be output before the setcookie () function. Otherwise, an error is returned.
Let's take a look at the following complete example:
So how do we know about cookies?
A simple answer is to reference the principle of cookie name. set the expires (cookie expiration time) parameter of the setcookie () function to a value smaller than the current time!
For example:
Setcookie ("username", NULL, mktime-3600 ,"/");
?>