note 65944 added to function.session-start

From: Date: Wed, 10 May 2006 13:00:00 +0000
Subject: note 65944 added to function.session-start
Groups: php.notes 
Request: Send a blank email to php-notes+get-111071@lists.php.net to get a copy of this message
Just a note for any of you who have the same trouble as I did. $_SESSION appears to break horribly if you attempt to assign information into integer keys. For example, a result from a MySQL query may look like: <?php array( 0 => 'haravikk', 'username' => 'haravikk', 1 => 'fish', 'password' => 'fish' ); ?> Attempting to assign that to $_SESSION either as a straight array, or by placing all keys (for example using a foreach) will FAIL and the data will be unavailable when you move to another page. My solution was to do this: <?php function storeSessionArray($array) { foreach($array as $k => $v) if (is_string($k)) $_SESSION[$k] = $v; } ?> This worked correctly =) ---- Server IP: 84.18.202.180 Probable Submitter: 82.41.161.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-start.php Edit -- http://master.php.net/note/edit/65944 Del: integrated -- http://master.php.net/note/delete/65944/integrated Del: useless -- http://master.php.net/note/delete/65944/useless Del: bad code -- http://master.php.net/note/delete/65944/bad+code Del: spam -- http://master.php.net/note/delete/65944/spam Del: non-english -- http://master.php.net/note/delete/65944/non-english Del: in docs -- http://master.php.net/note/delete/65944/in+docs Del: other reasons-- http://master.php.net/note/delete/65944 Reject -- http://master.php.net/note/reject/65944 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#111071) next »