我正在創建一個受密碼保護的網頁。 所有工作正常,但我的問題是,每當用戶從我的網頁複製一個URL並粘貼另一個瀏覽器,然後該頁面顯示相同的數據(我有一些網頁和所有頁面顯示相關數據)。那不是我想要的。我想這是自動進入登錄頁面。我需要相同的會話過期腳本 我的代碼如下所示。頁面重定向,如果我輸入直接url和會話過期
<?php
$host = ""; // Your host address to your database on your server. Usually "localhost". Check with your hosting provider
$user = ""; // Your username you set up for this database on your server
$pass = ""; // Your password you set up for this database on your server
$db = ""; // The database name that you will be connecting to
// Connecting to the MySQL database
mysql_connect($host, $user, $pass);
mysql_select_db($db);
if (isset($_POST['username'])) {
$username = $_POST['username'];
$password = $_POST['password'];
// Query to check to see if the username and password supplied match the database records
$sql = "SELECT * FROM users WHERE username='".$username."' AND password='".$password."' LIMIT 1";
$res = mysql_query($sql);
// If login information is correct
if (mysql_num_rows($res) == 1)
{
header('Location: done.php');
}
// If login information is invalid
else {
header('Location: error.php');
}
}
?>
謝謝!
第一個從不使用'mysql_ *它已經過時了。開始使用'mysqli_ *'。第二我沒有看到你的'session_start()'和'$ _SESSION ['username'] = $ username'是。沒有這些東西,你不能開始會議。 –
你可以使用它的Cookie或者使用一些加密的會話票務服務... –
首先,你的英語不能幫助你理解問題,而且你似乎需要使用會話對象,在某個地方啓動會話與session_start()和存儲登錄用戶的詳細信息,你可以用session_destroy()銷燬它,當你再次訪問該頁面,你必須檢查會話,如果沒有設置,那麼你可以重定向用戶登錄頁面 – Subash