How can sessions be counted in PHP without using MySQL?

Sessions can be counted in PHP without using MySQL by utilizing the $_SESSION superglobal array to store and update a counter variable. This counter variable can be incremented each time a new session is created or accessed. By keeping track of this counter within the session itself, you can effectively count the number of active sessions without the need for a database like MySQL.

<?php
session_start();

if (!isset($_SESSION['session_counter'])) {
    $_SESSION['session_counter'] = 1;
} else {
    $_SESSION['session_counter']++;
}

echo "Number of active sessions: " . $_SESSION['session_counter'];
?>