My session variables disappear about 1 in 10 times and I don’t understand why.
I have 2 scripts one which is called when the page is loaded: a.php
. It initializes the session variables and the session below.
a.php
<?php
header('Content-Type: application/json');
?>
<?php
session_start();
if (!isset($_SESSION['score'])) {
$_SESSION['score'] = 0;
$_SESSION['lives'] = 5;
....
when the user clicks something a second php script is run: b.php
. It has the exact same beginning, except this time the logical statement should be false, so the if statement should not be entered.
b.php
<?php
header('Content-Type: application/json');
?>
<?php
session_start();
if (!isset($_SESSION['score'])) {
echo "Something is wrong!"
....
For some reason about 1 in every 10 times I reload the page, the session variables are deleted between the first and the second script and the if statement in b.php
is entered and I don’t understand why.
I am using PHPstorm as an IDE and testing on localhost could it be some configuration issue with PHPstorm or my local php server?