我正试图学习如何使用PHPNerds。 我在管理他们提到的文字时遇到麻烦(我几乎理解该守则的内容,但我无法拿到哪一部法典将存放在哪部名称上)。 页: 1
User Login
<html>
<head>
<title>User Logon</title>
</head>
<body>
<h2>User Login </h2>
<form name="login" method="post" action="login.php">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
Remember Me: <input type="checkbox" name="rememberme" value="1"><br>
<input type="submit" name="submit" value="Login!">
</form>
</body>
</html>
Login Code
<?php
/* These are our valid username and passwords */
$user = jonny4 ;
$pass = delafoo ;
if (isset($_POST[ username ]) && isset($_POST[ password )) {
if (($_POST[ username ] == $user) && ($_POST[ password ] == $pass)) {
if (isset($_POST[ rememberme ])) {
/* Set cookie to last 1 year */
setcookie( username , $_POST[ username ], time()+60*60*24*365, /account , www.example.com );
setcookie( password , md5($_POST[ password ]), time()+60*60*24*365, /account , www.example.com );
} else {
/* Cookie expires when browser closes */
setcookie( username , $_POST[ username ], false, /account , www.example.com );
setcookie( password , md5($_POST[ password ]), false, /account , www.example.com );
}
header( Location: index.php );
} else {
echo Username/Password Invalid ;
}
} else {
echo You must supply a username and password. ;
}
?>
Validating
<?php
/* These are our valid username and passwords */
$user = jonny4 ;
$pass = delafoo ;
if (isset($_COOKIE[[ username ]) && isset($_COOKIE[ password )) {
if (($_POST[ username ] != $user) || ($_POST[ password ] != md5($pass))) {
header( Location: login.html );
} else {
echo Welcome back . $_COOKIE[ username ];
}
} else {
header( Location: login.html );
}
?>
提前感谢。