我正在制作登录用户的登录/登出课程,根据用户的选择设置cookie.用户输入他们的电子邮件/密码并检查数据库,电子邮件/密码组合是否存在创建会话,并设置了cookie(用户ID)并且用户被重定向...然后我有一个记录用户的功能通过获取该cookie中保存的用户ID,检查该用户ID是否存在,然后再次将用户数据保存在会话中...我想知道是否有人看到任何有关此事的错误/不安全的事情.
简短的例子,我相信你们可以得到它的要点......
function login($email, $password, $remember){
// Check the database for email/password combo
if(/*user exists*/){ // if the user exists
$_SESSION = /*User data*/ // save the users data in a session
if($remember){
setcookie('user_id', /*User id*/); // save the user id in a cookie
}
header("location: index.php");// redirect
}
}
function Check_Cookie(){
if(isset($_COOKIE['user_id'])){
return $this->Log_In_ID($_COOKIE['user_id']);
}else{
return false
}
}
function Log_In_ID($id){
//Check the database if the user id exists
if(/*user exists*/){ // if the user exists
$_SESSION = /*User …Run Code Online (Sandbox Code Playgroud)