有人可以帮我登录后自动注册,这是我的注册脚本......
if (empty($_POST) === false) {
$required_fields = array ('email', 'username', 'password', 'password_again', 'first_name', 'last_name');
foreach ($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true) {
$errors [] = 'ALL fields MUST be filled out correctly';
break 1;
}
}
if (empty($errors) === true) {
if (user_exists($_POST['email']) === true) {
$errors [] = 'Sorry, the email \'' . $_POST['email'] . '\' is already in use.';
}
if (preg_match("/\\s/", $_POST['email']) == true) {
$errors[] = 'Your email must not contain any spaces';
}
if (user_exists($_POST['username']) === true) {
$errors [] = 'Sorry, the username \'' . $_POST['username'] . '\' is already in use.';
}
if (preg_match("/\\s/", $_POST['username']) == true) {
$errors[] = 'Your username must not contain any spaces';
}
if (strlen($_POST['password']) < 6) {
$errors[] = 'Your password must be in between 6-24 characters long';
}
if ($_POST['password'] !== $_POST ['password_again']) {
$errors[] = 'Your passwords did not match';
}
}
}
?>
此代码仅注册用户,我希望它能够登录,请不要对此进行评分
答案 0 :(得分:1)
注册脚本结束
//include your login validation
if(empty($errors)){
//User->login(); or anything you use for validating logins
}
答案 1 :(得分:0)
要执行登录,您通常需要为用户创建一个cookie(使用PHP的setcookie函数)并初始化保存其用户数据的会话变量(如用户名)。
此链接将向您展示如何使用setcookie()http://php.net/setcookie
对于会话变量,它们可以像这样任意设置:
$ _ SESSION ['username'] =“Admin”;
创建安全登录脚本需要一些时间,因此我建议您使用已经存在的表单并根据您的需求进行调整。为了使其真正安全,您需要对数据库输入进行严格的健全性检查,使用校验和进行安全登录和表单发布,以及许多其他要考虑的因素。