Search code examples
phpsessionsession-cookiesreloadisset

Session not set till page reload?


So after a LOT of trial and error, I set up something to test whether my session is set or not, which looks like this :

<?php
session_start();
if (isset($_SESSION['email'])) {
    echo "Logged In!";
}
else {
    echo "NOT LOGGED IN!";
}
?>

And what I realize is that after Login ( which redirects to the site's homepage) The session is not set until I reload the entire homepagepage.

Has anyone experienced anything like this and/or knows how to get around such a problem?

Thanks in advance!


Solution

  • Thanks for all the help guys, but I found the problem. Apparently I have to be extremely specific with my url in the redirect file.

    I had header('location: http://domain.com');

    instead of

    header('location: http://www.domain.com');

    ...facepalm