php - What's the proper way to test for an unexpired cookie?


I'm having trouble getting my code to ignore loading an expired cookie.

When I log a user in who wants to be remembered, I set a cookie like so...

setcookie('mysiteCookieBlah', $token, $expiry, '/', '', 1, 1); 

Whenever they refresh the page, if they're not logged in ie don't have a user ID in session, I then check for the existence of the cookie to see if I should init auto-logging them in...


When they log out, I expire it...

setcookie('mysiteCookieBlah', "", time()-3600, '/', '', 1, 1);

Next time the page refreshes,

  $intiAutoLogin = ?

should = false, right? At the moment, it sees the cookie every time, regardless if it's expired.

Thanks for taking a look.




I changed my logout cookie code to

setcookie("mysiteCookieBlah", "", time()-3600, '/');

and it worked. I have no idea why.

People are also looking for solutions to the problem: php - Save textFile dates into MySQL


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.