I am running a login script which sets a session with the
user_id
$remember = $_POST['remember'];
user_id
user_name
if($password == $pass_word){
session_start();
$_SESSION['user_id'] = $user_id;
if($remember == "on"){
setcookie("user_name", $user_name, time()+2592000);
}
}
loggedin()
function loggedin(){
if((isset($_SESSION['user_id'])) || ((isset($_COOKIE['user_name'])) && (isset($_SESSION['user_id'])))){
return true;
} else {
return false;
}
}
I have fixed it. The cookie
was set but I have to restart the session
if the browser has been closed so this is my solution
// db connection here
function loggedin(){
if(isset($_SESSION['user_id']){
return true;
} else if(isset($_COOKIE['user_name']){
$query = mysqli_query($con, "SELECT id FROM users WHERE user_name='". $_COOKIE['user_name']."'");
$sql = mysqli_fetch_array($query);
$_SESSION['user_id'] = $sql['id'];
return true;
} else {
return false;
}
}