這是我db.classes登錄和註銷重定向後PHP
public function login($un, $pw)
{
$result = mysqli_query($this->dbh,"select username, password from users where username='$un' and password='$pw'");
$count=mysqli_num_rows($result);
if($count==1){
header("location:home.php");
}
else {
echo
"<script type='text/javascript'>
alert('LOG-IN FAILED!');
</script>";
echo '<script language="JavaScript"> window.location.href ="index.php" </script>';
}
}
這是我的PHP
<?PHP
include("db.classes.php");
$g = new DB();
$g->connection();
if(isset($_POST['subBtn']))
{
$un = $g->clean($_POST["uname"]);
$pw = $g->clean($_POST["pass"]);
$g->login($un, $pw);
}
$g->close();
?>
這裏是我的註銷按鈕
<div id="footer">
<li id="Login"><a href="index.php">Log Out</a></li>
</div>
我怎樣才能防止用戶在退出後無需重新登錄即可返回到前幾頁?
檢查會話是否爲空 –
登錄設置會話並註銷表示如果會話爲空,則取消會話重定向至index.php頁面 – Ramki
http://www.makeitsimple.co.in/PHP_loginexmp.php –