How can one check if a session is already running in PHP?

To check if a session is already running in PHP, you can use the session_status() function which returns the current session status. If the session is active, the function will return PHP_SESSION_ACTIVE.

if (session_status() === PHP_SESSION_ACTIVE) {
    echo "Session is already running";
} else {
    echo "Session is not running";
}