Re: [PHP] Session expires randomly
On Tue, 2005-09-06 at 19:43, Philip Hallstrom wrote: On Tue, 6 Sep 2005, Mauricio Pellegrini wrote: You were right! That was exactly the problem after reading your message, I 've verified the value for gc_maxlifetime and found that it was set to 1440 secs in other words 24 minutes. Thank you for that. But, now I need to come up with something to avoid this behaviour. The problem is that there's a second php application ruuning on the same server and I don't want to change the default for gc_maxlilfetime, Why not just change it on your pages? The manual says it can get changed anywhere... so just make a call to ini_set() on your pages and other scripts will remain unaffected. ? Well I`ve just tryed that but didn't work. I think that ini_set(session.gc_maxlifetime,28800) is useless, because after setting the value for gc.maxlifetime the scripts ends normally. I mean the html is displayed and the application waits for user input. But at that time ( after the script has finished ) the original value for session.gc_maxlifetime is restored (defaults to 1440). So , does any one have any other ideas? Thanks Mauricio So I was thinking on implementing some sort of automatic session refresh after a short period, let's say every 20 minutes of inactivity. And of course I should provide the users with a manual way to make session end, sort of a logout from the application.( no problem with that) My question is: Is there a way to set sort of a timer as to invoke an hipothetical refresh_session.php without reloading the current page on the client? Thanks Mauricio. On Fri, 2005-09-02 at 14:20, [EMAIL PROTECTED] wrote: On Fri, 2 Sep 2005, Mauricio Pellegrini wrote: Hi, I have this problem , When I start a Session everything seems to be ok but sometimes with no reason the session vanishes. All settings are default , I mean session_cache_expire is 180 min. I understand that this setting should make sessions last for at least 3 hours but in my case it seems not to be true since the real duration varies from 20 minutes to an hour I think the parameter you need to look at in php.ini is session.gc_maxlifetime. It sets the session lifetime, not session_cache_expire. The default lifetime is probably 1440 seconds, roughly 20 minutes, so the behavior you are seeing is completely normal - it's all working as it should. Kirk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Session expires randomly
So I was thinking on implementing some sort of automatic session refresh after a short period, let's say every 20 minutes of inactivity. And of course I should provide the users with a manual way to make session end, sort of a logout from the application.( no problem with that) My question is: Is there a way to set sort of a timer as to invoke an hipothetical refresh_session.php without reloading the current page on the client? Thanks Mauricio. Below is some code, in four parts, to do this with JavaScript's setTimeout() function. Since it is JavaScript, this will not work in browsers that don't support JavaScript or browsers in which the user has disabled JavaScript. Good luck! Kirk /* Part 1: Add this script to your page. */ // After 14 minutes on a single page a new window is opened, warning the // user that their session is about to expire. The user can then choose // to continue or end their session by pushing a button. The pop-window // will kill all Session info, redirect the main window to the // login page, and then close itself if the user decides to end the // session or, if after 58 seconds, the user has taken no action. script // 84 ms = 14 minutes setTimeout('sessionPop()', 84); /script /* Part 2: Have this JS function defined somewhere accessible by your page */ // function sessionPop() // called by setTimeout function in ./include/footer.inc // Does the following // 1. Open new window // 2. Write the HTML to the window. It is done this way so that there is no trip // to the server which could result in the Session being refreshed. function sessionPop() { x = window.open('', 'check', 'height=200, width=400, titlebar=yes, status=no, toolbar=no, menubar=no, location=no, resizable=yes, scrollbars=no'); x.document.write('htmlheadtitleSession About To Expire/title/headbodyimg src=./images/some_logo.gif width=58 height=50pDo you want to extend your session?form action=logout.php method=post name=refreshSess id=refreshSessinput type=submit name=sessionRefresh value=Yes. Extend Sessionnbsp;nbsp;input type=button value=No. Logout onClick=window.opener.location = \'logout.php\'; window.close();/form/bodyscriptfunction timeOut() {window.opener.location = logout.php; window.close();} setTimeout(timeOut(), 58000);/script/html'); // Need to reset the timer so the user will continue // to get the pop-up when they choose to extend the session // 84 ms = 14 minutes setTimeout('sessionPop()', 84); /* Part 3: Here is the content of logout.php */ ? /* logout.php is the handler for the form POST from the pop-up window generated by the javascript function 'sessionPop()' contained in ./include/jsFunctions.js. logout.php can also be arrived at from redirection due to a Session Timout on any application page. */ // sessionRefresh is the submit button to continue the Session. // If we get sessionRefresh in the POST close the window. POSTing // to the page keeps the Session alive. // Otherwise, this page has been reloaded from a redirect so kill // all Session info and redirect to home page. if (!$HTTP_POST_VARS[sessionRefresh]) { // Kill all current session info kill_session(); header(Location: $someURL); } else { ? html head title /title script language=JavaScript !-- window.close(); //-- /script /head body /body /html /* Part 4: Here is the definition of PHP function kill_session() */ function kill_session() { $name = session_name(); session_unset(); session_destroy(); setcookie($name, '', (time() - 2592000), '/', '', 0); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Session expires randomly
You were right! That was exactly the problem after reading your message, I 've verified the value for gc_maxlifetime and found that it was set to 1440 secs in other words 24 minutes. Thank you for that. But, now I need to come up with something to avoid this behaviour. The problem is that there's a second php application ruuning on the same server and I don't want to change the default for gc_maxlilfetime, So I was thinking on implementing some sort of automatic session refresh after a short period, let's say every 20 minutes of inactivity. And of course I should provide the users with a manual way to make session end, sort of a logout from the application.( no problem with that) My question is: Is there a way to set sort of a timer as to invoke an hipothetical refresh_session.php without reloading the current page on the client? Thanks Mauricio. On Fri, 2005-09-02 at 14:20, [EMAIL PROTECTED] wrote: On Fri, 2 Sep 2005, Mauricio Pellegrini wrote: Hi, I have this problem , When I start a Session everything seems to be ok but sometimes with no reason the session vanishes. All settings are default , I mean session_cache_expire is 180 min. I understand that this setting should make sessions last for at least 3 hours but in my case it seems not to be true since the real duration varies from 20 minutes to an hour I think the parameter you need to look at in php.ini is session.gc_maxlifetime. It sets the session lifetime, not session_cache_expire. The default lifetime is probably 1440 seconds, roughly 20 minutes, so the behavior you are seeing is completely normal - it's all working as it should. Kirk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Session expires randomly
On Tue, 6 Sep 2005, Mauricio Pellegrini wrote: You were right! That was exactly the problem after reading your message, I 've verified the value for gc_maxlifetime and found that it was set to 1440 secs in other words 24 minutes. Thank you for that. But, now I need to come up with something to avoid this behaviour. The problem is that there's a second php application ruuning on the same server and I don't want to change the default for gc_maxlilfetime, Why not just change it on your pages? The manual says it can get changed anywhere... so just make a call to ini_set() on your pages and other scripts will remain unaffected. ? So I was thinking on implementing some sort of automatic session refresh after a short period, let's say every 20 minutes of inactivity. And of course I should provide the users with a manual way to make session end, sort of a logout from the application.( no problem with that) My question is: Is there a way to set sort of a timer as to invoke an hipothetical refresh_session.php without reloading the current page on the client? Thanks Mauricio. On Fri, 2005-09-02 at 14:20, [EMAIL PROTECTED] wrote: On Fri, 2 Sep 2005, Mauricio Pellegrini wrote: Hi, I have this problem , When I start a Session everything seems to be ok but sometimes with no reason the session vanishes. All settings are default , I mean session_cache_expire is 180 min. I understand that this setting should make sessions last for at least 3 hours but in my case it seems not to be true since the real duration varies from 20 minutes to an hour I think the parameter you need to look at in php.ini is session.gc_maxlifetime. It sets the session lifetime, not session_cache_expire. The default lifetime is probably 1440 seconds, roughly 20 minutes, so the behavior you are seeing is completely normal - it's all working as it should. Kirk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Session expires randomly
Hi, I have this problem , When I start a Session everything seems to be ok but sometimes with no reason the session vanishes. I'm using PHP 4.3.4 as a Apache module. Apache version is 1.3 under Suse Linux 8.2 All settings are default , I mean session_cache_expire is 180 min. I understand that this setting should make sessions last for at least 3 hours but in my case it seems not to be true since the real duration varies from 20 minutes to an hour I use session_start() and then on any routine I verify the existence of certain session variables. Is the server expiring the session automatically for some reason? Thanks Mauricio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Session expires randomly
On Fri, 2 Sep 2005, Mauricio Pellegrini wrote: Hi, I have this problem , When I start a Session everything seems to be ok but sometimes with no reason the session vanishes. I'm using PHP 4.3.4 as a Apache module. Apache version is 1.3 under Suse Linux 8.2 All settings are default , I mean session_cache_expire is 180 min. I understand that this setting should make sessions last for at least 3 hours but in my case it seems not to be true since the real duration varies from 20 minutes to an hour I use session_start() and then on any routine I verify the existence of certain session variables. Is the server expiring the session automatically for some reason? Just a thought... normal file based sessions are stored in /tmp. Maybe your server has some process that is cleaning out files in /tmp that haven't been accessed in X amount of time.. Crazy thought, but maybe that's it... Try some tests... start a session, load a page, and have the page reload itself every minute (being sure to access/modify the session). Put some code in there so as soon as the session goes away it spits out the date/time and stops so you can see how long it lasted. Let that run for over an hour. See what happens. Try another one, but only reload the page every 20-30 minutes or something... good luck! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Session expires randomly
On Fri, 2 Sep 2005, Mauricio Pellegrini wrote: Hi, I have this problem , When I start a Session everything seems to be ok but sometimes with no reason the session vanishes. All settings are default , I mean session_cache_expire is 180 min. I understand that this setting should make sessions last for at least 3 hours but in my case it seems not to be true since the real duration varies from 20 minutes to an hour I think the parameter you need to look at in php.ini is session.gc_maxlifetime. It sets the session lifetime, not session_cache_expire. The default lifetime is probably 1440 seconds, roughly 20 minutes, so the behavior you are seeing is completely normal - it's all working as it should. Kirk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] session expires
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
[PHP] session expires
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. Thanks in advance! Andreas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] session expires
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. Why? Simply start a new session, keep the form variables in there and let the user log in again. I don't see any point in controling if the user used login - form - relogin process or went straight to the form, filled it in and then logged in for the first time. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] session expires
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. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] session expires on server side
session cookie exists on client side and it is set to last 5 days. the problem is that after some time session data expires. cookie on client side exists ($PHPSESSID), but session data on server side does not exists. i think that the answer is something like: ini_set(session.cache_expire, 7200); but i'm not sure. i need this fast, so thnx to anybody with a solution. Aljosa P.S. sorry for my bad english, here is the code: -- ?php $time = (60*60*24*5); ini_set(session.cache_expire, 7200); $date = gmdate (D, d M Y H:i:s) . GMT; header (Date: . $date); header (Expires: . $date); header (Last-Modified: . $date); header (Pragma: no-cache); header (Cache-Control: no-cache); session_set_cookie_params($time); ? -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] session expires on server side
Aljosa Mohorovic wrote: session cookie exists on client side and it is set to last 5 days. the problem is that after some time session data expires. cookie on client side exists ($PHPSESSID), but session data on server side does not exists. i think that the answer is something like: ini_set(session.cache_expire, 7200); but i'm not sure. i need this fast, so thnx to anybody with a solution. Aljosa P.S. sorry for my bad english, here is the code: Not too sure. Try messing with session.gc_maxlifetime. According to the php manual, this sets the length of time (in secs) before session data is cleared with the garbage collection routine. Padraig -- ?php $time = (60*60*24*5); ini_set(session.cache_expire, 7200); $date = gmdate (D, d M Y H:i:s) . GMT; header (Date: . $date); header (Expires: . $date); header (Last-Modified: . $date); header (Pragma: no-cache); header (Cache-Control: no-cache); session_set_cookie_params($time); ? -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php