TheLettuceMaster
TheLettuceMaster

Reputation: 15744

PHP Cookie Not Expiring Correctly

I have a cookie, I believe, set to expire 1 second after it is created (for testing purposes). It is taking 5 second however. If I set it to .5, it goes down to about 3 seconds. I have sliced the script down to the basics and still have this issue.

 <?php setcookie("test", "daily_deals_cookie", time() + 1); ?>
 <?php
    if (!isset($_COOKIE['test'])) {
       echo "COOKIE NOT SET";
    } else {
       echo "<h3 style=\"font-family: sans-serif; \">Please come back again!</h3>";
    }
  ?>

Does anyone see something I am missing here?

Upvotes: 0

Views: 882

Answers (2)

user1474090
user1474090

Reputation: 675

When it comes to web development you often have to expect that tasks are not done exactly when asked. These can be due to many reasons such as the load on the client machine, one big issue i have found is that settimeout is often not called at the requested time interval.

Therefore you should build some flexibility into your app that handles time lags on the browser.

Upvotes: 0

Tschallacka
Tschallacka

Reputation: 28742

time difference between server and end user computer. processing queque of end user computer.

when testing, try to hold it about 15 seconds, so your browser can patch it in at a more accurate time in the queque.

Cookie lifetime is a pretty low priority management process that easily gets bumped to the back for a redraw of the viewport or other business.

Upvotes: 1

Related Questions