我有如下代码:
<?php
require 'database/db.php';
if($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["userid"];
$password = $_POST["password"];
if (empty($name) || empty($password)) {
header("Location : AdminLogin.php?status=failure");
exit();
}
$count = verifyUser($name, $password);
if($count == 1 )
{
header("Location : AdminLogin.php?status=success");
}
else {
header("Location : AdminLogin.php?status=failure");
}
exit;
}
?>
<?php include('inc/header.php'); ?>
<div class = "section page">
<div class ="wrapper">
<div class="page-header">
<b>Admin Login </b>
</div>
<?php if(isset($_GET["status"]) AND $_GET["status"]=="success") { ?>
<p> Your login was a success .. I will redirect you to another page.</p>
<?php } else {?>
<form method="post" class="form-signin" action="AdminLogin.php">
<h2 class="form-signin-heading">Sign In</h2>
<input type="text" name ="userid" class="input-block-level" placeholder="UserID...">
<input type="password" name ="password" class="input-block-level" placeholder="Password...">
<button class="btn btn-large btn-primary" type="submit">Sign in</button>
</form>
<?php } ?>
</div>
</div>
<?php include('inc/footer.php'); ?>
一旦我点击登录按钮,我就会在服务器端对用户进行验证,并返回一个 int(应该是 bool,我同意)登录是否成功。
我正在重定向到同一页面。
发现 ...
我已验证 $count 已正确返回。即如果用户名和密码匹配 count = 1 否则 count !=1 。到目前为止,一切都很好。我也注意到它在那之后失败了。
谢谢加根
编辑:验证用户(这只是一个存根)
function verifyUser($username, $password)
{
return strcmp ( $username , $password )
}