In my login php page, after I check if the user's info is saved in the database, I set a session:
$_SESSION['username'] = $user;
if (isset($_SESSION['username'])) {
header( 'Location: index.php' );
}
and put session_start();
on this page at the tippy top.
Then it redirects me to index.php
, telling me that the session has been set. On this page, I put session_start();
at the top but in the login area, I type:
<?php if (!isset($_SESSION['username'])) { echo $_SESSION['username'];?><a href="/login.php"><li class="cat_0" id="login_btn_1">Login / SignUp</li></a>
<?php }
else {?>
<span id="login_show"><a href="/account/user.php?u=<?php echo $_SESSION['username'];?>" id="username_btn"><?php echo $_SESSION['username']; ?><a href="/account/logout.php?logout=1" id="logout_btn">LOGOUT</a></a></span>
<?php }?>
but every time, even if I reload, it shows the result for the !isset()
, so that is telling em the session variable is not set. I check in my chrome cookies settings and it shows that PHPSESSID
is set each time I test the Login. Can anyone explain why my session is not starting or what the problem is?