W3docs

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
}

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Learn PHP sessions</div>

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