note 123404 added to function.session-status

From: Date: Thu, 06 Dec 2018 16:47:59 +0000
Subject: note 123404 added to function.session-status
Groups: php.notes 
Request: Send a blank email to php-notes+get-209857@lists.php.net to get a copy of this message
Use always session_status(), to check if a session is already started and active. if(session_status() !== PHP_SESSION_ACTIVE) session_start(); or if(session_status() === PHP_SESSION_NONE) session_start(); Don't use if(!isset($_SESSION)) session_start(); or if(session_id() === "") session_start(); They will not work properly after a call to session_write_close(). Both functions will continue to report, that the session exists. And this is right, you can read from $_SESSION, but if you want to write, you need session_start() again. As a shorthand you can use @session_start() with the @ at the beginning to suppress the PHP notice "A session had already been started - ignoring session_start()" As stated in the manual for session_start(), a second call will do no harm, it will be simply ignored. But you need the @, if you don't want to get the notice. ---- Server IP: 208.43.231.9 Probable Submitter: 178.1.187.1 ---- Manual Page -- http://php.net/manual/en/function.session-status.php Edit -- https://master.php.net/note/edit/123404 Del: integrated -- https://master.php.net/note/delete/123404/integrated Del: useless -- https://master.php.net/note/delete/123404/useless Del: bad code -- https://master.php.net/note/delete/123404/bad+code Del: spam -- https://master.php.net/note/delete/123404/spam Del: non-english -- https://master.php.net/note/delete/123404/non-english Del: in docs -- https://master.php.net/note/delete/123404/in+docs Del: other reasons-- https://master.php.net/note/delete/123404 Reject -- https://master.php.net/note/reject/123404 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#209857) next »