【发布时间】:2009-09-13 05:11:27
【问题描述】:
我正在创建一个登录/注销类来让用户登录,根据用户的选择设置 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 data*/ // save the users data in a session
header("location: index.php");// redirect
}else{
return false;
}
}
这不是我试图询问的详细示例,但我确信您可以了解它的要点......有人认为这有什么潜在的问题吗?如果你们有任何建议,我很乐意听到它们......另外,你们是使用 oop 来登录用户,还是使用其他任何方式。
【问题讨论】:
标签: php security cookies login