What could be causing the session variable to increment by 2 instead of 1 in the PHP script provided?

The issue could be caused by the script being included or executed multiple times within the same session, causing the session variable to increment by 2 instead of 1. To solve this issue, we can add a check to see if the session variable already exists before incrementing it.

<?php
session_start();

// Check if the session variable exists
if (!isset($_SESSION['count'])) {
    $_SESSION['count'] = 0;
}

// Increment the session variable by 1
$_SESSION['count']++;

echo "Session count: " . $_SESSION['count'];
?>