5

Basically what I am trying to achieve is this, the below does not work but you should get the idea.

if (session_status() == PHP_SESSION_ACTIVE) {
  show specific icons
}
else
{
  don't show specific icons
}

What am I doing wrong. How can I reliably check if a session is started in php 5.4. I have read somewhere that this is the recommended way.

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278

2 Answers2

3

session_status is available for PHP v5.4 and later, maybe that's why.

You can try with session_id :

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).

Just what you need for PHP below 5.4 ! ;)

Cyril N.
  • 38,875
  • 36
  • 142
  • 243
1

// You can Create your variable and check, exist it.

For example

session_name('My_SESSION_HUMANS'); // Create a unique instance of your session variables
session_start();
if(!empty($_SESSION['my_var']))
{
   // IF Session exist.
}
else
{
   // Oops no Session ?
   $_SESSION['my_var'] = 'Yeahaaah!!!!';
}
Jan Czarny
  • 916
  • 1
  • 11
  • 29