0
votes

I've a strange problem with $_SESSION variables in PHP.

page1.php sets

$_SESSION['progress'] = 1;

In page2.php, I have the following code:

if ($_SESSION['progress'] === 1) {
   $_SESSION['progress'] = 2;
}

Both files start with session_start(). page1.php contains a link which calls page2.php.

If I log the $_SESSION['progress'] variable, it doesn't change at all. Why? Are $_SESSION variables more like constants: once defined they can't be changed again? Are there any similar techniques? I basically need something to track the progress of several users. A database is not an option.

Thank you!

2

2 Answers

0
votes

Maybe try == instead of ===

if ($_SESSION['progress'] == 1) {
   $_SESSION['progress'] = 2;
}
0
votes

Try to do this:

if(isset($_SESSION["progress"]))
{
    if($_SESSION["progress"] == 1)
    {
        $_SESSION["progress"] = 2
    }  
}