if (!isset($_COOKIE['visited'])){ //如果cookie不存在,则新建 setcookie("visited","www.phpddt.com",mktime()+86400,"/") ordie("客户端禁止cookie"); echo"欢迎首次访问本站";}else{ echo"欢迎再次访问本站"; //如果cookie存在}?>
Session management mechanism only cookie and session of the two mechanisms, then to small talk about, cookies and session application!
(1) A cookie is a small text file that holds user names, passwords, personalization settings, and so on, when a user visits a website,
Will generate such a file saved in the user's computer, the General browser will keep the cookies in their own temporary files!
It is important to note that for security reasons, cookies do not keep high-secret information such as bank account numbers!
To generate a cookie using the Setcookie () function in PHP, consider the following simple example:
!--? php if (! Isset ( $_post [ ' username ' ]) {//form showing form without submission ?; < form method = "POST" action = "" > Please enter your name: < input type = "text" name = " Username " value = "!--? php echo $_cookie[' username ']?--"; < input type = "Submit" value = "Commit" ; !--
form
;
}else { if (! Empty($_post[' username '])) {Setcookie ("username",$_post[' Username '],mktime () +86400,"/"); Echo "Your name is logged in"; } Else { echo"name cannot be empty";}} ?>
You can see that the Setcookie () function mainly receives 6 parameters:
Name:cookie's name (required)
The value of the Value:cookie
Expires:cookie Expiration Time (required)
Path: "/" means that all arrays of this domain can be accessed and read
Domain:cookie valid domain name
The Secure:bool value, if true, indicates that the cookie is sent to the client only when the SSL-encrypted connection
In particular, it is important to note that the Setcookie () function cannot output any scripts before the error occurs.
Take a look at the following complete example:
So how do we clear cookies?
It's simple. The name of the cookie, set the Expires (cookie expiration time) parameter of the Setcookie () function to be less than the current time!
Such as:
setcookie("username",NULL,mktime-3600,"/");?>
Original address ...
'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
'). Text (i)); }; $numbering. FadeIn (1700); }); });
The above describes the PHP session management cookie Introduction, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.