0

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...

Marcel
  • 15
  • 2
  • 7
  • 5
    Please provide us with your code. Even if we visit your website, we can't see the PHP code behind it. It's impossible for us to tell what's going on. – icecub Sep 28 '16 at 20:35
  • here is for example sign out code. When I try to sign out I can do that many times and it takes time when actually session is NULL. On another webhosting or local server WAMP it works how it should. No problem with it. – Marcel Sep 28 '16 at 21:03
  • Check your PHP log for "Headers already sent" errors and fix them. See http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php – Barmar Sep 28 '16 at 21:16
  • http://php.net/manual/en/function.session-destroy.php – RiggsFolly Sep 28 '16 at 21:16

2 Answers2

0

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.

Craig Jackson
  • 362
  • 2
  • 9
  • Hi Craig yes that is another problem that reply doesn't show up immediately. It takes time. session_start() is in the header as first thing. this problem is only with my web hosting nowhere else. I can also keep signing out and sometimes it works sometime no... – Marcel Sep 28 '16 at 21:05
0

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

Marcel
  • 15
  • 2
  • 7