note 99867 added to function.session-id

From: Date: Sat, 11 Sep 2010 14:46:25 +0000
Subject: note 99867 added to function.session-id
Groups: php.notes 
Request: Send a blank email to php-notes+get-172482@lists.php.net to get a copy of this message
I had a lot of trouble with session_regenerate_id() as it did not regenerate... Session_id() stayed the same no matter what (unless closing the window). I wanted to have different sid and empty vars for each session/page meeting a condition for security reasons. Finally, this worked: <?php $a = session_id(); if ($a == '') session_start(); if ( ...add check if you want to regenerate and destroy vars on some condition only [recommended :)]... ) { session_unset(); //destroys variables session_destroy() //destroys session; } $a = session_id(); if ($a == '') session_start(); if (!isset($_SESSION['safety'])) { session_regenerate_id(true); $_SESSION['safety'] = true; } $_SESSION['sessionid'] = session_id(); ?> Now you get different sid and session variables empty for each session_start if condition is met (i.e. user hits refresh on user/password form, which I needed badly :). Hope this helps someone out there. Env: localhost Note: condition is mandatory, otherwise it destroys on each load. ---- Server IP: 69.147.83.197 Probable Submitter: 88.118.32.3 ---- Manual Page -- http://www.php.net/manual/en/function.session-id.php Edit -- https://master.php.net/note/edit/99867 Del: integrated -- https://master.php.net/note/delete/99867/integrated Del: useless -- https://master.php.net/note/delete/99867/useless Del: bad code -- https://master.php.net/note/delete/99867/bad+code Del: spam -- https://master.php.net/note/delete/99867/spam Del: non-english -- https://master.php.net/note/delete/99867/non-english Del: in docs -- https://master.php.net/note/delete/99867/in+docs Del: other reasons-- https://master.php.net/note/delete/99867 Reject -- https://master.php.net/note/reject/99867 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#172482) next »