two days ago we shared a cookie in Java to record the page last access time method, today we come to talk about how to implement the cookie in PHP , you can choose according to their favorite language!
//Control page display encoding
Header ("Content-type:text/html;charset=utf8");
//cookie record whether the page was first visited by the tag
$flag = false;
//First detect if there is a value for lastvisit this key in the cookie.
$lastVisit = isset ($_cookie[' lastvisit ') "$_cookie[' lastvisit ']: ';
if ($lastVisit) {
Setcookie () must be written before the Echo statement, or it will be due to HTTP reasons, PHP error
If you really want to put the Echo statement behind it, you need to turn on the OB cache
Setcookie (' lastvisit ', date (' y-m-d h:i:s ', Time ()), Time () +3600);
$flag = true;
Echo ' Your last access time: '. $lastVisit;
}
//Description is the first time you visit this page
if (! $flag) {
Setcookie (' lastvisit ', date (' y-m-d h:i:s ', Time ()), Time () +3600);
Echo ' Your first visit to this page! ';
}
?>
Today we mention a concept: OB caching. This knowledge point is very important, and very practical value, another day I will open a special course to talk about it, we look forward to! Share to this end, local tyrants feel good, just give it a reward !
The above describes the PHP cookie real-combat tutorial, including the content, I hope the PHP tutorial interested in a friend helpful.