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, '/', 'https://www.mysite.com', 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...
if(isset($_COOKIE['mysiteCookieBlah'])) $intiAutoLogin=true; else $intiAutoLogin=false;
When they log out, I expire it...
unset($_COOKIE['mysiteCookieBlah']); setcookie('mysiteCookieBlah', "", time()-3600, '/', 'https://www.mysite.com', 1, 1);
Next time the page refreshes,
if(isset($_COOKIE['mysiteCookieBlah'])) $intiAutoLogin = ?
should = false, right? At the moment, it sees the cookie every time, regardless if it's expired.
Thanks for taking a look.