Here's what I'm trying to do:
login.php (called from login.html):
<?php
session_start();
$loggedin = false;
if($username == "xxxx" && $userpwd == "xxxx"){
$loggedin=true;
session_register("loggedin");
}
if($loggedin){
header("Location: index.php?".SID);
} else {
header("Location: login.html");
}
?>
index.php:
(very first lines of the file)
<?php
session_start();
if(!$loggedin){
header("Location: login.html");
}
?>
(further down we have this)
<a href="logout.php?<?php echo SID; ?>">Logout</a>
logout.php:
<?php
session_start();
session_destroy();
header("Location: login.html");
?>
track_vars is on
register_globals is on
The first time through, everything works as expected. Login page runs login script and I get a session id that I can pass around. When I click the logout link, I am logged out (I think) and redirected to the login page. If I try to log in again, I get no session id (just question marks after the url's) and I can go back to index.php without any redirect occurring. Also, if I don't log back in, I can still get to index.php.
I'm trying to accomplish a redirect if the user isn't logged in yet to avoid skipping it altogether - and it works well if I haven't logged in yet. After I log out, or try to go to the index page without the session id while still logged in, this mechanism doesn't work.
Is there something I'm missing/is there a better way to do this?
Thanks for any help.