How I can check in PHP if SESSION exists but is null.
I have really old self made platform, where visitor can log in as "guest", it sets $_SESSION "guest"
but it is NULL
.
Now I wan't to show some specific content to only registered. If I check isset($_SESSION['guest']), is_null($_SESSION['guest'])
or is_null($_SESSION['guest'] === FALSE
they all return same.
How I can check if guest session exists but is null
?
Try this:
if(isset($_SESSION['guest']) && is_null($_SESSION['guest']))
{
// your code
}
if($_SESSION['guest'] == "")
{
// code
}
You can try using empty
instead, for example:
session_start();
if(isset($_SESSION['guest']) && !empty($_SESSION['guest'])) {
//Session is not null or empty
}
else
{
//Session is null or empty
}