Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session expiration and session_start and set_save_handler

Status
Not open for further replies.

thedaver

IS-IT--Management
Joined
Jul 12, 2001
Messages
2,741
Location
US
I'm using MySQL to build a session handler db. Part of my design is to kill off old sessions (10 minutes, 1200 seconds) as fast as possible.

I plan to 'require_once' a single PHP file for 1) my MySQL routines for the handler, 1) the session_set_save_handler setup for the routines, 3) and the correct sequence of calls to test the session for expiration.

I believe the following is correct, and would function as desired:
===============================
'stuff.php' pseudocode

function session_open;
function session_close;
function session_read;
function session_write;
function session_destroy;
function session_gc;

session_set_save_handler (all the routines above)

session_start();

{my code to test if the session already was open and has expired, if it has, destroy the session and divert the user with a 'header()' call to a "re-login" page, otherwise don't touch the session}

session_start();
============================================

I think I need the first call to session_start() to get all the session_handler stuff setup and working (load $_SESSION, etc). That way I can test the age of the session versus my limit in the next code.

The second session_start() probably isn't even necessary

anybody see a problem here?












Surfinbox.com Business Internet Services - National Dialup, DSL, T-1 and more.
 
Platform is LAMP: linux (redhat 7.3), apache (1.3.29), mysql (3.23.56), and PHP (4.3.4). Sorry for the omission.

Surfinbox.com Business Internet Services - National Dialup, DSL, T-1 and more.
 
Don't use your own code to check for session expiry. Let PHP do it.

The most surefire way to ensure that old sessions are destroyed in a timely manner is to set session.gc_probability to 100. That way, every time session_start() is invoked, the garbage collection will fire off.

I have a FAQ on using MySQL to store session data. faq 434-2037

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top