Re: PHP 4 Sessions

From: Date: Thu, 31 Aug 2000 19:23:23 +0000
Subject: Re: PHP 4 Sessions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-14666@lists.php.net to get a copy of this message
> Assuming the user has cookies turned off for his/her > browser... > * Does php4 store session information in a server side > cookie? If so, how? If you configure PHP with --track-vars then the session ID will automagically be appended to all relative URL's you use on your pages if the user has disabled cookies (or if you turn the use of cookies off in php.ini), if the user has cookies enabled then cookies will be used instead. > * Do you have to store session variables in a database, > using a "session id" as the (primary)key and retrieve > the variables thusly? You can do that by using session_set_save_handler() to define your own callback functions for the session API, then you choose where to store session data (in a database, on a ftp server or whereever). If you do not use your own functions, then PHP will by default store session data in files in /tmp (one file per session). By editing php.ini you can also get PHP to store sessions in memory. > * Should you use the function > "session_set_save_handler()" (and the associated > user defined functions) > to create your own server side "cookies" (per se)? I think I answered this one above. > One thing that wasn't addressed was how these files > (cookies?) deleted if a user just closes down his/her > browser on one of my pages? Php.ini contain the options session.gc_probability and session.gc_maxlifetime The first one defines how often the garbage collector should run (this is the percentual probability that the gc will run when a new session is started). The second one defines for how long a session may be inactive before being deleted by the garbage collector. So if you set session.gc_probability = 50 and session.gc_maxlifetime = 600 Then there is a 50% chance that the garbage collector will run every time a new session is started, and every time the gc runs it will delete sessions that have not been active within the last 600 seconds. I hope that was helpfull :-) Best regards, Jesper Juhl juhl@eisenstein.dk

« previous php.general (#14666) next »