简体   繁体   中英

PHP Sessions doesn't work correctly

Hi I am learning PHP and trying to build forum as a start. Forum You can do the test and see how login session doesn't respond properly. username: test password:test

 <?php
//signout.php
include 'connect.php';
include 'header.php';

echo '<h2>Sign out</h2>';

//check if user if signed in
if(isset($_SESSION['signed_in']) && $_SESSION['signed_in'] == true)
{
    //unset all variables
    $_SESSION['signed_in'] = NULL;
    $_SESSION['user_name'] = NULL;
    $_SESSION['user_id']   = NULL;
    $_SESSION['user_level']   = NULL;


    echo 'Succesfully signed out, thank you for visiting.';
    echo " test";
}
else
{
    echo 'You are not signed in. Would you <a href="sign_in.php">like to</a>?';
}

include 'footer.php';
?>

You can log in but then through some pages it looks like you are not signed in or when trying to sign out it doesn't sign out properly.

The problem is with sessions on my web hosting server. Locally on my computer it works fine under WAMP. Tested another web hosting it works fine.

Not sure what is it...

How are you handling your sessions on each page? It seems like it is generally set up properly, I have replied to "Topic Test" and it reports I have successfully replied, but it does not show up in the list.

The one thing that has messed me up in the past is forgetting to put session_start(); at the top of the page, or in a function that feeds that page. Your session data will still be there but will not be accessible to the page and will not record any session data you try to store.

Just quick update

Problem was not with my script but with web hosting and "Unixy Varnish enabled". I had to disable it.

Thank you for all the help

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