Home >Backend Development >PHP Tutorial >PHP Cookie practical tutorial

PHP Cookie practical tutorial

WBOY
WBOYOriginal
2016-07-29 09:09:07965browse

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! ';

                                                                                   Today we mentioned a concept: OB cache. This knowledge point is very important and of great practical value. I will open a special course to talk about it another day, so stay tuned! This ends the sharing. If you think it’s a good talk, please give me a reward

!



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.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn