• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
on-session-end functions?

Hello again Smile

How do I go about having code igniter perform functions when the session ends?


I am storing some information, unique to a session to too large for session variables, so I am storing it in the database using session_id as the row ID in the table..

So when the session ends (whether by closing the browser, timing out, or logging out, two of which are out of my control) I want to write a function that goes into the database and deletes anything identified by that session...

this would require my code being triggered by session destroy, but process immediately before the session is actually ended..


I know I can just add my function into the sess_destroy function in the session library..

is sess_destroy always used to end the session.. or is there some kind of automatic process when the browser is closed or when session times out?

It's only called when you call it manually.

You're best bet is to have a cron job that runs whenever, and in your table, you can have the time that the users session ends (you'll need to refresh it every time the user makes a request to your server). If any rows have a date set in the past, they are old and can be deleted. Hope this helps.

okay so how would i go about doing this to toggle the 'online' field in the 'users' table, so that when a search for users is displayed, in the last_login column i want it to display 'online' if the user is online...

my initial method was to have the field toggled to true in my login function, and toggled to false in the sess_destroy function....

is there a way to check for all open sessions? if so i can have a database field set to session_id every login.. then run a chron job run every (few minutes?) to match all open session id's to my user table and any session id found in the database thats not open will toggle online field to false..

or is there an easier way?

duh, session database, working now Smile thanks

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.