note 54885 deleted from function.setcookie by danbrown

From: Date: Sun, 17 May 2009 17:59:42 +0000
Subject: note 54885 deleted from function.setcookie by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155047@lists.php.net to get a copy of this message
Note Submitter: lharkleroad at gmail dot com ---- In response to Snupha's note, one way to get the desired result on the server side, and therefore work around the user's local date and time, is to store your session information in a sessions table in your database. For example: 1. Create a sessions table in your favorite db with a 32 char sessionid column, modifed and created datetime columns, and any other columns that you want to associate with the session such as a userid. 2. In your PHP script, create a variable containing the 32 char unique ID for your session, and store the result in a sessionid cookie that expires at the end of the browser session, and also insert it in a new row in your sessions table. 3. When your scripts check for the existance of the sessionid cookie, if a value is returned, they would check against the sessions table in your database to find the matching ID, updating the modified datetime for that record to keep the session active. If the server time elapsed since the record was modified exceeds your timeout constraints, you can force the user to reauthenticate and issue them a new session ID if desired. 4. If you require a login to some part of your site, you can also update the session record with the userid to link the session to the user. I decided to use this method on a recent project where both PHP and ColdFusion needed to access the same datasource for different applications. The result is a language-independent session in which multiple web servers on the same domain (but potentially different sub-domains) can know when the user has logged in and allow them to continue the session on the other server. Otherwise, using the sessions built in to PHP and ColdFusion would require separate logins when switching between applications programmed in the two languages. Going a little further with this, you can then report stats on the sessions table for the average session length by comparing the created and modified columns, or get a session history for a particular user. I hope this helps a few people. Have fun!

« previous php.notes (#155047) next »