我遇到了问题。当我点击<a href="logout.php"> Logout </a>
时,我有一个重定向到 login.php ,但是如果我再次打开 home.php ,那么没有重定向和用户留在系统。我的意思是没有会话毁灭。
这是代码:
的login.php
<?php
session_start();
if (isset($_POST['submit']))
{
include("config.php");
$username=$_POST['username'];
$password=$_POST['password'];
$_SESSION['login_user']=$username;
$query = mysql_query("SELECT username FROM login WHERE username='$username' and password='$password'");
if (mysql_num_rows($query) != 0)
{
echo "<script language='javascript' type='text/javascript'> location.href='home.php' </script>";
}
else
{
echo "<script type='text/javascript'>alert('User Name Or Password Invalid!')</script>";
}
}
?>
home.php
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<h1>Welcome
<?php
session_start();
$login_session=$_SESSION['login_user'];
echo $login_session;?> </h1>
<a href="logout.php"> Logout </a>
</body>
</html>
logout.php
<?php
session_start();
if(session_destroy())
{
header("Location: login.php");
}
?>