note 76241 deleted from function.session-start by peehaa

From: Date: Fri, 09 Dec 2016 22:11:11 +0000
Subject: note 76241 deleted from function.session-start by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208330@lists.php.net to get a copy of this message
Note Submitter: (zero)luke(zero)(at)gmail(dot)com ---- Regarding the posts discussing ways of checking if a session is active, I've found that this is the best way, aslong as you dont assign any variables to the $_SESSION superglobal before calling the function. The Function: <?php function session_started(){ if(isset($_SESSION)){ return true; }else{ return false; } } ?> An Example: <?php function session_started(){ if(isset($_SESSION)){ return true; }else{ return false; } } //Start the output buffer so we dont create any errors with headers ob_start(); //Check to see if it has been started if(session_started()){ echo 'The session has been started.<br />'; }else{ echo 'The session has not been started.<br />'; } //Start the session echo 'Starting Session...<br />'; session_start(); //Check again if(session_started()){ echo 'The session has been started.<br />'; }else{ echo 'The session has not been started.<br />'; } //Flush the buffer to screen ob_end_flush(); ?> Hope this helps some people.

« previous php.notes (#208330) next »