New To PHP/Session Timeout Question

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
drdexter33
Forum Newbie
Posts: 5
Joined: Mon Jun 02, 2008 12:39 pm

New To PHP/Session Timeout Question

Post by drdexter33 »

I'm more of a .Net Developer, however, I've been asked to help out with a PHP application.

One of the requirements is to persist a forms data if and when a session timeout occurs.

I'm thinking of checking to see if the session id is valid when a user clicks to save a form and if the session id is not valid, saving it either to a cookie or to the database.

Sound reasonable?

Thanks.

Doug
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: New To PHP/Session Timeout Question

Post by califdon »

Welcome to the world of PHP, Doug.

The first thing you have to keep in mind is that PHP is a server script, so by the time the browser sees a page, the PHP is gone until called again. What I'm saying is that the only thing that can detect a user's actions is a client script, namely Javascript. So if you're trying to take some action when the user clicks a button, that has to be done in Javascript, even if that action is to call another PHP script on the server. That second script could check for a valid session id and do something, like save values to a database. But this really shouldn't be necessary, I think. Since you control the creation of the session initially, the only things that might cause it to be killed are: 1) the user closes his browser window, 2) the session timeout that you control times it out, or 3) the server crashes. If the latter is a concern, you might need to do this, otherwise I don't see the need. I don't think I'd create a client cookie, because then you'd have to deal with the possibility that the user might log out and not log in for months, but the cookie would still be there and probably invalid, the next time they visit the site.
drdexter33
Forum Newbie
Posts: 5
Joined: Mon Jun 02, 2008 12:39 pm

Re: New To PHP/Session Timeout Question

Post by drdexter33 »

Ok!

Thanks for your help califdon!

Doug.
Post Reply