note 63701 added to function.session-set-save-handler

From: Date: Tue, 28 Mar 2006 19:04:05 +0000
Subject: note 63701 added to function.session-set-save-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-106867@lists.php.net to get a copy of this message
With regards to the read handler, the docs say: "Read function must return string value always to make save handler work as expected. Return empty string if there is no data to read." I can't emphasize this enough. I just spent half a day trying to figure out why my sessions weren't storing any information. I was blithely returning the results of a query on the database from the read handler. Since there was no match for the new ID, the result was NULL. Since it wasn't a string, sessions were essentially disabled. So, the safe thing might be something like this: <?php function sessRead($id) { // Look up data $results = getStuff($id); // Make sure it's a string settype($results, 'string'); return $results; } ?> Of course, you can do whatever you want with it. But, no matter what, make sure you return a string. HTH, Michael ---- Server IP: 64.71.164.2 Probable Submitter: 64.218.24.130 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.session-set-save-handler.php Edit -- http://master.php.net/note/edit/63701 Del: integrated -- http://master.php.net/note/delete/63701/integrated Del: useless -- http://master.php.net/note/delete/63701/useless Del: bad code -- http://master.php.net/note/delete/63701/bad+code Del: spam -- http://master.php.net/note/delete/63701/spam Del: non-english -- http://master.php.net/note/delete/63701/non-english Del: in docs -- http://master.php.net/note/delete/63701/in+docs Del: other reasons-- http://master.php.net/note/delete/63701 Reject -- http://master.php.net/note/reject/63701 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#106867) next »