"John W. Holmes" <[EMAIL PROTECTED]> skrev i meddelandet news:[EMAIL PROTECTED] > Andreas Magnusson wrote: > > > Hi, I wonder if anyone knows of a way to detect if a session has expired > > (when your session.cookie_lifetime != 0). > > I've tried to see if the session-vars are unset, but that doesn't seem to be > > the case, still everythings seems to be lost. > > My problem is that I have a page which the user must log in to in order to > > access it (I use sessions for this). > > This page contains a form which may take some time to fill in. > > Now the session may expire during this time and all data will be lost. > > My plan is to allow the user to login again without losing the data but this > > requires me to know if the session has expired. > > If you set $_SESSION['user'] and at some point it's not set anymore, > then the session expired. Start a new one, throw the form data into the > session ($_SESSION['post'] = $_POST), allow the user to log in and > redirect back to form processing page, extract post data ($_POST = > $_SESSION['post']), and process the form.
Yup, that's basically what I do. Anyway the problem was that I did something stupid (as always). I do a redirect at the end of the page if the headers are not sent, because I have a lot of tests (if:s) and for each fail and some of the successful ones I want to redirect the user back to the main-page. So I trusted that if I wrote some HTML, the headers would've been sent and no redirect performed. No need to say that that was a bad thing to trust. Now I do an exit after emitting HTML instead. Thanks for your help! Andreas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php