search

Home  >  Q&A  >  body text

A question about Cookies in php. Please ask for help.

I am a bad student == I don’t know how to learn a lot by myself. I want to ask a question from a master. The code in the book is as follows:

<?php

date_default_timezone_set("Etc/GMT-8 ");

if(!isset($_COOKIE["visittime"])){ //If the cookie does not exist

setcookie("visittime",date("y-m-d H:i: s")); //Set a Cookie variable

echo "first time to meet:".date("y-m-d H:i:s")."<br>"; //Output string

}else{ //If Cookie exists

setcookie("visittime",date("y-m-d H:i:s"),time() 60); //Set variables with Cookie expiration time

echo "last time:".$_COOKIE["visittime"]; //Output the time of the last visit to the website----------- --------------

echo "<br>"; //Output carriage return character

}

echo "now : ".date("y-m-d H:i:s"); //Output the current access time *********************


?>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

Rendering For:

First load:

O$Q[CK%[NM6]TKYD17YK_]X.png

Second Refresh times:

C04I6~A0OPO1S(LRYV0~X$X.png

Question: What I want to ask is == created a new cookie file, re-execute this command. Why is the time in setcookie() in the line in the remarks changed to the current time date("y-m-d H:i:s"), and then there is -------- in the remarks? - The line can also output the last time instead of the current time. Then, there is *********** in the remarks but the output is the current time, which is correct== What's going on? What's going on when the line of ------------- arrives? God, please help. T T

奔跑吧 少年奔跑吧 少年2589 days ago1115

reply all(1)I'll reply

  • 寻觅 beyond

    寻觅 beyond2017-10-12 23:21:37

    PHP Chinese manual says this

    Before setting a cookie for the same parameter again, you must delete it first. If the value of the parameter is an empty string or FALSE, and the other parameters are still the same as the last call to setcookie, the specified name will be deleted by the remote client.

    Hope this solves your problem


    reply
    0
  • 奔跑吧 少年

    Although it is a bit difficult to understand, you may need to think about it carefully, but thank you for the guidance ٩( 'ω' )و

    奔跑吧 少年 · 2017-10-12 23:38:05
  • Cancelreply