note 76241 added to function.session-start

From: Date: Fri, 06 Jul 2007 22:55:00 +0000
Subject: note 76241 added to function.session-start
Groups: php.notes 
Request: Send a blank email to php-notes+get-128274@lists.php.net to get a copy of this message
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. ---- Server IP: 194.145.210.3 Probable Submitter: 62.136.145.130 ---- Manual Page -- http://www.php.net/manual/en/function.session-start.php Edit -- https://master.php.net/note/edit/76241 Del: integrated -- https://master.php.net/note/delete/76241/integrated Del: useless -- https://master.php.net/note/delete/76241/useless Del: bad code -- https://master.php.net/note/delete/76241/bad+code Del: spam -- https://master.php.net/note/delete/76241/spam Del: non-english -- https://master.php.net/note/delete/76241/non-english Del: in docs -- https://master.php.net/note/delete/76241/in+docs Del: other reasons-- https://master.php.net/note/delete/76241 Reject -- https://master.php.net/note/reject/76241 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128274) next »