嗨,这个话题的所有读者都在这里!我知道这听起来很愚蠢,但我想用php制作一些简单的注册和登录表单。这不是一个网站,所以它不应该是安全的,我不希望名称和密码永远持续下去。我还想指出我是初学者,我只知道php的基础知识。首先,我开始编写html登录表单,然后登录php以检查是否有任何cookie。注册是为了以后。 这是代码:
<?php
setcookie($usr,$pwd,time() + (86400 * 30),'/');
setcookie($pwd,$usr,time() + (86400 * 30),'/');
If(isset($_POST['submitForm'])) {
$usr = $_POST['usr'];
$pwd = $_POST['pwd'];
If(isset($_COOKIE[$usr]) && isset($_COOKIE[$pwd])) {
}
else {
die('User has not been registered or wrong username or password.');
}
}
?>
正如你所看到的,我试图接受代表“密码”的密码。使用代表&#39;用户名&#39;的$ usr变量,两者都使用cookie。
以下是HTML代码:
<form method="POST" action="logged.php" style="text-align: center;">
<h1>Log In Page of Forum</h1>
<input type="text" name="usr" placeholder="Username">
<br/><br/>
<input type="password" name="pwd" placeholder="Password">
<br/><br/>
<input type="submit" name="submitForm" value="Log in">
<br/>
</form>
是。 PHP在文件中。
弹出的错误是:
Notice: Undefined variable: usr in logged.php on line 2
Notice: Undefined variable: pwd in logged.php on line 2
Notice: Undefined variable: pwd in logged.php on line 3
Notice: Undefined variable: usr in logged.php on line 3
但文字仍然出现:
User has not been registered or wrong username or password.
我这样做是为了更好地理解PHP,而不是认真对待它。
有人能告诉我我的代码有什么问题吗?我提前谢谢你。 ;)