简体   繁体   中英

PHP: Overwritting $_SESSION variable

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!

Try to do this:

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

Maybe try == instead of ===

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM