Ok with the help of Allahverdi here is script I am using:
Form action = login_process.php
PHP Code:
<?php
session_start();
$username = $_POST['user'];
$password = $_POST['pwd'];
if($username == "tony" && $password == "king888"){
$_SESSION['logineduser'] = "tony";
header("Location: /main/index.php");
}
else{
header("Location: index.php?error=true");
}
?>
That works fine as far as I can tell. Error traps and message diplays at this snippet:
PHP Code:
<?php if($_GET['error']){
echo"<b>Password is incorrect!</b></font>";
}
?>
The login directs fine to another directory (/main/) to a new "protected" index.asp with the following code:
PHP Code:
<?php
session_start();
if(!$_SESSION['logineduser'] || $_SESSION['logineduser'] != "tony"){
header("Location: index.php?error=2222");
}
if($_GET['logout']){
unset($_SESSION['logineduser']);
header("location: ../index.php");
}
?>
For some reason beyond my knowledge, the logout session doesn't actually clear the session? After clicking "log out" the user is taken back to the main index page which is what I want, but they can now view any url directly by typing it in the browser bar. If I close the browser and try to hard link it, it throws up a weird error about the page isn't redirecting properly. Anyone know why? And how to get this top function differently, or is this just the drawback of using a session instead of a cookie?
Edit: Here is the link on the protected page to logout:
Code:
<a href="../?logout=true">Logout</a>
Bookmarks