How to check if session is already started?


I’m using session_start() to initiate the session and then assign a value in session global variable. But sometimes I get an error on session_start() saying session is already started. So is there a way to check if session is already started or not to get rid of such errors?

Also please suggest if there is any better way rather than checking existances of session.


when you start the session for the first time, set a session variable and it could be anything.
eg… $mySessVar = ‘qwerty’;

Then when you want to check if a session is runing, simply check for the existance and value of $mySessVar.

if(isset($mySessVar) && $mySessVar == 'qwerty'){
          //session is running
} else {
         //session is not running