<?PHPif(!isset($_cookie[' Visittime '])) {#use $_cookie to get Visittime, execute the following statement block if it does not exist, or else Setcookie(' Visittime ',Date(' y-m-d h-i-s '));#generate a Visittime cookie. Echo"You are the first to enter the website. ";}Else{ Setcookie(' Visittime ',Date(' y-m-d h-i-s ')); Echo"The last time you visited the site was:".$_cookie[' Visittime ']. " #Use the $_cookie global variable to invoke the Visittime cookie. } Echo"The time you visit this website is:".Date(' y-m-d h-i-s '); ?>
The effect is as follows:
The URL is re-enter once.
You can also write:
<? if(! Isset($_cookie[' Cookie ']) { setcookie(' Cookie ', ' Hello World '); Echo "You don't have a cookie yet," he said. "There's a second visit! ";} Else { echo "You now have a cookie. And your cookie is:". $_cookie[' COOKIE '?>
The END
Follow Baidu Learn php[10]-read Cookie case