note 119397 deleted from function.session-destroy by mazzanet

From: Date: Sun, 29 May 2016 09:38:00 +0000
Subject: note 119397 deleted from function.session-destroy by mazzanet
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-205611@lists.php.net to get a copy of this message
Note Submitter: akam at akameng dot com ---- The manual says: "To use the session variables again, session_start() has to be called." this means that you need to call session_start() after session_destroy() example: First of all, if you called session_start() before no need to call it again, the example that provided here assume that you didn't started session, if you do before, then don't call session_start() again. <?php function logout(){ //session_start() $_SESSION = array(); if (ini_get("session.use_cookies")) { $params = session_get_cookie_params(); setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"] ); } session_destroy(); //starting session again here, or in somewhere else //session_start(); } if( !$myconfition ){ logout(); //the best practice here is to redirect or reload //or if you want to keep user in same page, and you need // to use a session again, then start session session_start(); } ?> It depends on your code structure, be sure that you started session after session_destroy();

« previous php.notes (#205611) next »