简体   繁体   中英

php SESSION gets destroyed after redirection

I have a page where I set a value to a SESSION but when I redirect to another page ex. index.php that value I put to that SESSION doesn't exist anymore!

<?php
    session_start();
    // this is the page where I set a value to a SESSION called var!
    $SESSION['var'] = "hello";

    if(isset($SESSION['var'])){
        echo "Yes it is";
        header("location: test.php");
        exit();
    }
    else {
        echo "No it isnt";
    }
?> 

And this is the test.php where I get the SESSION undefined error!

<?php
    session_start();

    if(isset($SESSION['var'])){
        echo "Yes it is";
    }
    else {
        echo "No it isnt";
    }
?>

Ass you can see, I put session_start(); in both pages but still nothing!

Any help would be much appriciated, thank you!

PS Im using XAMPP

To access session variables you need to access the $_SESSION . Change $SESSION to $_SESSION. Hope this helps.

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