Check if session expired

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dimxasnewfrozen
Forum Commoner
Posts: 84
Joined: Fri Oct 30, 2009 1:21 pm

Check if session expired

Post by dimxasnewfrozen »

I am creating a cookie

Code: Select all

setcookie("USERID","$userid",time()+3600,"/",".mydomain.org",0);
If the cookie expires, it will just go back to the log in page. I need to show some sort of indication that the cookie expired instead of just showing the log in page. Ex: "Your session has expired. Please log back in." Is there a way of detecting that the cookie expired?
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Check if session expired

Post by Jade »

Just check to see if they have the cookie and if the http_referrer came from your website. If there's no cookie and the referrer was your own website then you know they were logged in but the session expired.
Post Reply