gpt4 book ai didi

php - 我试图在 php 中创建一个固定密码的登录表单

转载 作者:可可西里 更新时间:2023-11-01 00:58:05 26 4
gpt4 key购买 nike

我尝试在 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>

<?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;
}
?>

最佳答案

正如我在你的代码中看到的,密码是这样定义的

$password = $name = "";

因此,当您与空值进行比较时,而不是与表单中的 $_POST 值进行比较时。

比较会

 elseif ($_POST['password']!== $x) {

期待对你的帮助

关于php - 我试图在 php 中创建一个固定密码的登录表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35478535/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com