Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if $_SESSION superglobal exists in PHP

Tags:

php

session

People also ask

How do I check if a session variable exists?

You can check whether a variable has been set in a user's session using the function isset(), as you would a normal variable. Because the $_SESSION superglobal is only initialised once session_start() has been called, you need to call session_start() before using isset() on a session variable.

How can I see all session variables in PHP?

Use this: echo '<pre>'; var_dump($_SESSION); echo '</pre>'; Or you can use print_r if you don't care about types.

What is $_ session in PHP?

PHP $_SESSION is an associative array that contains all session variables. It is used to set and get session variable values.


if (isset($_SESSION['errors']))
{
    //Do stuff
}

use isset() and empty() php function.

if (isset($_SESSION['errors']) && !empty($_SESSION['errors'])) {
    // ...
}