中打開的選項卡中註銷時,我正在使用php中的php會話概念。創建登錄頁面使用jQuery和PHP和創建會話的所有頁面時,我登錄會話運行我可以在另一個標籤中打開登錄的URL在其中工作很好,但我有一個問題在註銷。註銷所有打開的選項卡,當用戶在php
當我註銷其中一個打開的瀏覽器選項卡時,其他選項卡仍然會手動運行,如果我刷新頁面會被註銷。我的要求是,當我註銷其中一個選項卡的其他選項卡應自動註銷而不是手動。
DB文件
<?php
session_start();
$con = mysqli_connect("localhost", "root", "","testing") or die ("Oops! Server not connected"); // Connect to the host
?>
的login.php
<?php
include 'db.php';
if(isset($_SESSION['username']) && $_SESSION['username'] != '')
{ // Redirect to secured user page if user logged in
echo '<script type="text/javascript">window.location = "userpage.php"; </script>';
}
?>
<html>
<body>
<form>
<table class="mytable">
<tr>
<td>Username</td>
<td>
<input type="text" name="username" id="username" class="as_input" value="s"/>
</td>
</tr>
<tr>
<td>Password</td>
<td>
<input type="password" name="password" id="password" class="as_input" value="s"/>
</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="login" id="login" class="as_button" value="Login »" />
</td>
</tr>
</table>
</form>
</body>
</html>
歡迎主頁
<?php
include 'db.php';
if(!isset($_SESSION['username']) || $_SESSION['username'] == '')
{
echo '<script type="text/javascript">window.location = "login.php"; </script>';
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="as_wrapper">
<h2>
welcome to home page
</h2>
<a href="logout.php" class="a">logout</a><br><br>
<a href='#'>test link</a>
</div>
</body>
</html>
logout.php
<?php
include 'library.php';
session_destroy();
unset($_SESSION['username']);
unset($_SESSION['password']);
echo '<script type="text/javascript">window.location = "login.php"; </script>';
?>
http://stackoverflow.com/questions/13513874/logout-all-open-tabs-automatically-when-user-logs-out-in-one-of-them – rocky
謝謝@rocky。 – Sjay
[當用戶註銷其中一個時自動註銷所有打開的選項卡]的可能重複(http://stackoverflow.com/questions/13513874/logout-all-open-tabs-automatically-when-user-logs-out-其中一個) –