Jump to content


Photo

Update MySQL Database When Session Ends


  • Please log in to reply
5 replies to this topic

#1 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 03 October 2006 - 11:44 PM

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

#2 MCP

MCP
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 03 October 2006 - 11:54 PM

yes, but you'll have to write your own session handling functions for all session related options. See
http://ca.php.net/ma...ave-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.

#3 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 05 October 2006 - 12:43 AM

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.

#4 Hi I Am Timbo

Hi I Am Timbo
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 05 October 2006 - 12:59 AM

not without javascript.  The only action is when a php script is called.

#5 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 05 October 2006 - 01:16 AM

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

#6 Hi I Am Timbo

Hi I Am Timbo
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 05 October 2006 - 01:23 AM

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();






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users