How to check if a PHP session is empty?
To check if a PHP session is empty, you can use the empty() function.
To check if a PHP session is empty, you can use the empty() function. For example:
How to check if a PHP session is empty?
<?php
session_start();
if (empty($_SESSION)) {
// The session is empty
}Info
Watch a video course: Learn PHP sessions
Alternatively, you can check if the $_SESSION array has a count of zero:
How to check if the $_SESSION array is empty in PHP?
<?php
session_start();
if (count($_SESSION) == 0) {
// The session is empty
}Note that $_SESSION is always defined, but it will only contain data after calling session_start().