I want my website to be accessed either by session or cookie. But after writing this code, the page needs both condition to be true instead of one. What's wrong here?
<?php
if(((isset($_SESSION['SUCCESS']) && $_SESSION['SUCCESS'] != "") ||
(isset($_COOKIE['is_logged_in']) && $_COOKIE['is_logged_in'] != ""))
== false){
$_SESSION['ERROR'] = "Please login first";
header('location: login.php');
}
?>
No need to write == false
. Try with removing it
if((isset($_SESSION['SUCCESS']) && $_SESSION['SUCCESS'] != "") ||
(isset($_COOKIE['is_logged_in']) && $_COOKIE['is_logged_in'] != "")
){
$_SESSION['ERROR'] = "Please login first";
header('location: login.php');
}
if(isset($_COOKIE['is_logged_in']) && $_COOKIE['is_logged_in'] != ""){
if(!isset($_SESSION['SUCCESS'])){
$_SESSION['SUCCESS'] = true;//or whatever you want
}
}
And then check session
if(!isset($_SESSION['SUCCESS']) || $_SESSION['SUCCESS'] == ""){
$_SESSION['ERROR'] = "Please login first";
header('location: login.php');
}else{
//move to home page
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.