tags:

views:

323

answers:

3

i have a third party script and was wondering how i can check with php if session_start() has been declared before doing something?

something like if(isset($_session_start())) { //do something }
+1  A: 
if(isset($_SESSION)) {
    // do something
}
Rob
+2  A: 

I suppose you could use the session_id function :

session_id() returns the session id for the current session or the empty string ("") if there is no current session (no current session id exists).

Or maybe testing whether $_SESSION is set or not, with isset, might do the trick, as it should not be set when no session has been started -- you just have to hope that nothing assigns anything to $_SESSION without starting the session first.

Pascal MARTIN
+2  A: 
function session_started(){ return !!session_id(); }
DUzun
Don't be too clever ;). I'd prefer 'return (session_id() !== "")'.
middus