Home >Backend Development >PHP Tutorial >PHP Cookie practical tutorial
Two days ago we shared how to use Cookie in Java to record the last visit time of a page. Today we will talk about how to use Cookie in PHP. You can choose according to your favorite language!
//Cookie records whether the page is the first time Visited tag $flag = false;
// First check whether there is a value for the lastVisit key in the cookie
use use using ’s to ‐ ‐ ‐ ‐ $ : ''; (If ($ Lastvisit) {
// setcookie () must be written before the echo statement, otherwise it will be due to http, pHP error // If you really want to put it on the Echo statement, After that, you need to enable ob cache
setcookie('lastVisit', date('Y-m-d H:i:s', time()), time()+3600); $flag = true; Visit time: '.$lastVisit; ()),time()+3600); echo 'This is your first time visiting this page! ';
!
The above has introduced the PHP Cookie practical tutorial, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.