Hi everyone,
I am using PHP to create the login and logout function in my website. I am using the "session" method. It seems that login works well, but the logout does have the problem. I can always use the "back" button in the browser to get back to the private site. Although when I clicked the "back" button, I got the "expired" information as I expected, as long as I clicked the "refresh" button, the private site would appear again.
Could anybody tell me what the wrong is here? Thank you so much!
Rong
My login.php:
<?
session_start();
if($name && $pass)
{
require("lib/connect.inc");
$query="select count(*) from auth where user='$name' and pass =
password('$pass')";
$result=mysql_query($query);
require("lib/runquery.inc");
$result=mysql_query($query);
if(mysql_result($result,0,0)>0)
{
$valid_user=$name;
session_register("valid_user");
}
}
if(session_is_registered("valid_user")){
require("private.html");
}
else
{
if (isset($name))
echo "<h2>You enter the incorrect username or password. Please
retry.</h2><br>";
else
echo "<h2>You are not logged in.</h2><br>";
}
My logout.php:
<?
session_start();
$old_user=$valid_user;
$result=session_unregister("valid_user");
$destroy= session_destroy();
if (!empty($old_user))
{
if($result && $destroy)
require("home.html");
else
echo "<h2>could not log you out.</h2>";
}
else
echo "<h2> You were not logged in, and so have not been logged
out.</h2>";
?>