快速提问...我的登录页面现在可以正常工作,因此当用户输入正确的信息时,它会将他们重定向到会话中的主页。当他们输入错误信息时,它只会将他们重定向回登录页面。
我想要做的是,当他们输入错误信息时,我希望它仍然将他们重定向到登录页面,但我希望它说无效登录,请再试一次。我试图回应它,但它只是刷新页面没有回应它..
登录页面
<?php include '../../view/header.php'; ?>
<div id="main">
<?php
// Inialize session
session_start();
// Check, if user is already login, then jump to secured page
if (isset($_SESSION['username'])) {
header('Location: ../../admin');
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<h3>Admin Login</h3>
<table>
<form method="POST" action="loginproc.php">
<tr><td>Username</td><td>:</td><td><input type="text" name="username" size="20"></td></tr>
<tr><td>Password</td><td>:</td><td><input type="password" name="password" size="20"></td></tr>
<tr><td> </td><td> </td><td><input type="submit" value="Login"></td></tr>
</form>
</table>
</body>
</html>
</div>
<?php include '../../view/footer.php'; ?>
登录过程.php
<?php
// Inialize session
session_start();
// Include database connection settings
require_once('database.php');
// Retrieve username and password from database according to user's input
$login = mysql_query("SELECT * FROM user WHERE (username = '" . mysql_real_escape_string($_POST['username']) . "') and (password = '" . mysql_real_escape_string($_POST['password']) . "')");
// Check username and password match
if (mysql_num_rows($login) == 1) {
// Set username session variable
$_SESSION['username'] = $_POST['username'];
// Jump to secured page
header('Location: ../../admin');
}
else {
// Jump to login page
header('Location: index.php');
}
?>