How can the PHP code be modified to prevent the values from increasing with each call?

The issue of values increasing with each call can be solved by storing the value in a session variable and updating it accordingly. By checking if the session variable exists, we can prevent the values from increasing on each call.

<?php
session_start();

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

echo "Counter: " . $_SESSION['counter'];
?>