Answer the question
In order to leave comments, you need to log in
Why are cookies not working in php?
Hello. I have a very strange problem.
I set cookies in php, after which I redirect to the private part of the site. But for some reason, cookies are simply not set and I am thrown back to the main page (due to a script that checks authorization). But after that, if I log in, these cookies appear from somewhere. In what there can be a trabl?
Authorization code:
$time = time()+60*60*24*30;
$id = $result->ResponseObject->ID;
setcookie("id", $id, $time);
setcookie("hash", Users::StringEncode($id), $time);
header("Location: /home");
public static function CheckAuth(){
if(isset($_COOKIE['id']) && isset($_COOKIE['hash'])){
$id = $_COOKIE['id'];
$hash = $_COOKIE['hash'];
if(self::StringEncode($id) == $hash) return true;
else return false;
}else{
return false;
}
}
Answer the question
In order to leave comments, you need to log in
Like this:
setcookie("hash", Users::StringEncode($id), $time, '/');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question