我有我的網頁登錄系統。您創建用戶名和密碼,然後返回主頁以使用正確的登錄詳細信息登錄。我輸入我的詳細信息,它讓我進來,並提出一個警告框,說「歡迎回來」。當我點擊確定後,它會簡要顯示網頁,然後直接回到登錄頁面。我已經開始會話,因爲註冊頁面正常工作。任何想法爲什麼登錄頁面是這樣做的?php登錄會話
的代碼如下所示:
if(empty($_POST['client_username']) || empty($_POST['client_password'])) {
die('You did not fill in a required field');
}
$qry = sprintf("SELECT client_username, client_password FROM client WHERE client_username = '%s' LIMIT 1", mysql_real_escape_string($_POST['client_username']));
$result = mysql_query($qry);
if($result) {
if(mysql_num_rows($result) == 0) {
die('That username does not exist in our database.');
}
}
$info = mysql_fetch_assoc($result);
if(md5($_POST['client_password']) != $info['client_password']) {
die('Incorrect password, please try again.');
}
$client_id = mysql_query("SELECT* FROM client WHERE client_id = '$client_id'");
$qry = sprintf("UPDATE client SET client_last_access = NOW() WHERE client_username = '%s'", $info['client_username']);
if(!mysql_query($qry)) {
die('Error: ' . mysql_error());
} else {
$_SESSION['client_username'] = $info['client_username'];
$_SESSION['client_password'] = $info['client_password'];
$_SESSION['client_id'] = $client_id;
echo '<script>alert("Welcome Back");</script>';
echo '<meta http-equiv="Refresh" content="0;URL=pv.php">';
}
什麼是pv.php?您使用該頁面作爲url回顯元刷新標記。 –
pv.php是主頁,它不應該在那裏? – mayman212
你是否在任何地方調用'session_start()'? – steveo225