note 68738 added to function.session-unset

From: Date: Tue, 08 Aug 2006 23:54:22 +0000
Subject: note 68738 added to function.session-unset
Groups: php.notes 
Request: Send a blank email to php-notes+get-115708@lists.php.net to get a copy of this message
You should know that on recent PHP only the first one of these functions works correctly. And if you use the other two, var_dump will print you the result you expected (session cleaned up), but the session file on the server won't be cleaned up. So use the first one. <?php function session_clean1($logout=false) { $v=array(); foreach($_SESSION as $x=>$y) if($x!="redirector"&&($x!="user"||$logout)) $v[]=$x; foreach($v as $x) unset($_SESSION[$x]); return; } function session_clean2($logout=false) { foreach($_SESSION as $x=>$y) if($x!="redirector"&&($x!="user"||$logout)) unset($_SESSION[$x]); return; } function session_clean3($logout=false) { $s=($logout||!isset($_SESSION["user"]))?array(): array("user"=>$_SESSION["user"]); if(isset($_SESSION["redirector"])) $s["redirector"]=$_SESSION["redirector"]; $_SESSION=$s; } ?> On previous php (<<5.1.4) releases at least the third one worked correctly. ---- Server IP: 195.70.37.52 Probable Submitter: 81.183.131.189 ---- 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-unset.php Edit -- https://master.php.net/note/edit/68738 Del: integrated -- https://master.php.net/note/delete/68738/integrated Del: useless -- https://master.php.net/note/delete/68738/useless Del: bad code -- https://master.php.net/note/delete/68738/bad+code Del: spam -- https://master.php.net/note/delete/68738/spam Del: non-english -- https://master.php.net/note/delete/68738/non-english Del: in docs -- https://master.php.net/note/delete/68738/in+docs Del: other reasons-- https://master.php.net/note/delete/68738 Reject -- https://master.php.net/note/reject/68738 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115708) next »