How to check if a PHP session is empty?

To check if a PHP session is empty, you can use the empty() function. For example:

<?php

if (empty($_SESSION)) {
  // The session is empty
}

Watch a course Learn object oriented PHP

Alternatively, you can check if the $_SESSION array is set and has a count of zero:

<?php

if (isset($_SESSION) && count($_SESSION) == 0) {
  // The session is empty
}

Note that the $_SESSION array is only available if a session has been started using the session_start() function.