我尝试在php中创建一个固定密码的登录表单。这是我的表单,它不显示错误消息,我喜欢创建用户名,没有问题,但密码是常量,如ex:abcd它是每个用户名的密码
<form action="test.php" method="POST">
<div class="logintable ">
<table class="applyfont" style="border: 1px solid lightseagreen">
<tbody>
<tr id="login1">
<td class="applyfontbold"><b>Login page </b></td>
</tr>
<tr>
<td style="padding-right:10px;">
<input type="text" name="name" value="" placeholder="Username or Email" id="uname">
<span>
<?php if(isset($_GET['nameErr']))
echo $_GET['nameErr'];
?>
</span>
</td>
</tr>
<tr>
<td>
<input type="password" name="password" value="" placeholder="Password" id="password">
<span>
<?php if(isset($_GET['passeErr']))
echo $_GET['passeErr'];
?>
</span>
</td>
</tr>
<tr>
<td>
<p class="submit"><input type="submit" name="save" value="Submit"> </p>
</td>
</tr>
<tr>
<td>
<div class="login-help applyfontlighter">
<p>Forgot your password? <span id="footer"><u style="color:red;"><a href="#">Click here to reset it.</a></u></span></p>
</div>
<p id="new"><button type="button" class="btn btn-default btn-xs" >New Registers</button></p>
</td>
</tr>
</tbody>
</table>
</div>
</form>
&#13;
<?php
$passeErr = $nameErr = "";
$password = $name = "";
$x = "typepass";
if (isset($_POST['save'])) {
if (empty($_POST['name'])) {
$nameErr = "Name is required";
header("Location:http://localhost/Archimage/login.html?nameErr=$nameErr");
} else {
$name = test_input($_POST['name']);
}
if (empty($_POST['password'])) {
$passeErr = "password is required";
header("Location:http://localhost/Archimage/login.html?passeErr=$passeErr");
} elseif ($password !== $x) {
$passeErr = "password doesn't match";
header("Location:http://localhost/Archimage/login.html?passeErr=$passeErr");
} else {
$password = test_input($_POST['password']);
}
echo "Username : " . $name . "<br>" . "Password :" . " " . $password;
}
?>
&#13;
答案 0 :(得分:2)
正如我在您的代码中所看到的,密码定义如下
$.ajax({
url: "/url",
dataType: 'text',
success: function(result){ alert(result); },
error: ErrorMsg,
});
因此,当您与空值进行比较时,而不是与表单中的$ _POST值进行比较。
比较将是
$password = $name = "";
期待帮助
答案 1 :(得分:2)
使用这个并测试它
elseif ($_POST['password'] !== $x) {
您在此处将密码与空值匹配。 所以这不会起作用。