晚上,
我在做饼干的噩梦。我尝试了100万种方法来保持用户登录但失败。
我的login.php
<?php
require_once('config.php');
if( $user->is_logged_in() ){ header('Location: index.php'); exit(); }
if(isset($_POST['submit'])){
if (!isset($_POST['username'])) $error[] = "Please fill out all fields";
if (!isset($_POST['password'])) $error[] = "Please fill out all fields";
$username = $_POST['username'];
if ( $user->isValidUsername($username)){
if (!isset($_POST['password'])){
$error[] = 'A password must be entered';
}
$password = $_POST['password'];
if($user->login($username,$password)){
$_SESSION['username'] = $username;
header('Location: index.php');
exit;
} else {
$error[] = 'Wrong username or password or your account has not been activated.';
}
}else{
$error[] = 'Usernames are required to be Alphanumeric, and between 3-16 characters long';
}
}
?>
以及在页面顶部当前需要使用用户登录的页面上。
if( $user->is_logged_in() ){ header('Location: profile.php'); exit(); }
关于如何向现有脚本添加cookie的任何建议?我不太擅长PHP,因此需要一些基本但安全的东西。谢谢大家!