Jump to content

Archived

This topic is now archived and is closed to further replies.

RTS

Update MySQL Database When Session Ends

Recommended Posts

Is there a way to have a database automatically be updated when the session times out?

Share this post


Link to post
Share on other sites
yes, but you'll have to write your own session handling functions for all session related options. See
http://ca.php.net/manual/en/function.session-set-save-handler.php

There's even an example there for file-based sessions which you might want to extend. You'll want to put your database update in the _close and/or _gc functions.

Share this post


Link to post
Share on other sites
well, I realized there is a problem with doing that on my site, so I have another question. Is there a way to update the database when a user leaves the site? that would work better.

Share this post


Link to post
Share on other sites
hmmmmm... could someone explain how to do what was suggested first? the tutorial confused me, and I didnt get what I was supposed to do...

Share this post


Link to post
Share on other sites
I've never done this before, but it looks like you define functions with the same names as these:

session_set_save_handler("open", "close", "read", "write", "destroy", "gc");

Then when named action occurs, it runs that function.  You would have to include this file on all of your pages, likely before you do session_start();

Share this post


Link to post
Share on other sites

×

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.