aandrade Posted September 30, 2007 Share Posted September 30, 2007 Hi, I'm trying to run into mysql database whenever users login and logout. I've manage to register when users login and when the users logout when clicking on the Logout link. The next step is the following: How could I detect when a session is about to expire so I can run a php script that inserts the logout info into the database? Say everyone gets kicked out of the session when the system has been idle for 3 hours. So after 3 hours of the system been unused the system has to login again. Just before the session expires how can I write to my db who was loged out? Thanks in advance. Churris Quote Link to comment https://forums.phpfreaks.com/topic/71250-run-php-script-when-session-is-about-to-expire/ Share on other sites More sharing options...
Wuhtzu Posted September 30, 2007 Share Posted September 30, 2007 I'm not a shark when it comes to sessions. I use them but I don't know the whole "theoretical background". As far as I know you can't check when a session times out or have the act of a session timing out start any event. So all you can do is check whether or not the session still exists... Set a cron job to run every x minutes to check whether or not $_SESSION['something'] exists and if it don't write to your database. Of course you can't check for $_session['something']... you have to check for a session id still being present or something like that. I hope someone else can pop by with some more knowledge Wuhtzu Quote Link to comment https://forums.phpfreaks.com/topic/71250-run-php-script-when-session-is-about-to-expire/#findComment-358415 Share on other sites More sharing options...
Ninjakreborn Posted September 30, 2007 Share Posted September 30, 2007 That is going to be VERY hard to accomplished. he's right the cron job should do comparisons. Set it up to check at one time for what sessions are there. 10 minutes later check again for any that are not there that were there and log. (means they logged off or whatever so record it). Then do it again every 30 minutes to keep tabs. Aside from that, you can check on other languages, and maybe if you can install something you can get an app, or session utility that can do something like that on the server possibly but I have never heard about one before. Quote Link to comment https://forums.phpfreaks.com/topic/71250-run-php-script-when-session-is-about-to-expire/#findComment-358424 Share on other sites More sharing options...
aandrade Posted October 2, 2007 Author Share Posted October 2, 2007 Thanks guys, its pretty good ide to have a crond job checking this but thinking about that, I think I've got to consider also when the user actually loged out the propper way by using a logout. Thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/71250-run-php-script-when-session-is-about-to-expire/#findComment-359907 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.