Im making a login/logout class that logs users in, sets cookies based on user's choice. The user enters their email/password and it checks the database, email/password combo exists a session is created, and a cookie is set (with the users id) and the user is redirected... I then have a function that logs users in by taking the user id saved in that cookie, checking whether that user id exists and then saving the users data in a session yet again... i was wondering if anybody see's anything potentialy wrong/unsafe about this.
Short Example, im sure you guys can get the gist of it...
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;
}
}
Its not a detailed example of what im trying to ask, but im sure you can get the gist of it... Does anybody see anything potentially wrong with this. If you guys have any recommendations id love to hear them...also, do you guys use oop to log users in, or any other ways.