Jump to content

Run php script when session is about to expire


aandrade

Recommended Posts

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.  ;D

Churris

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.