Follow Baidu Learn php[10]-read Cookie case

Source: Internet
Author: User
Tags learn php setcookie

<?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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.