Answer the question
In order to leave comments, you need to log in
Cookies are not saved, what could be the problem?
Good afternoon! I have one problem with cookies, I can not figure it out.
I have a method which checks the user's data during authorization, after which it creates cookies. I enter data on the main page, they are sent to a script file in which
require_once ("../classes/user.php");
$new_user = new User($_POST);
$new_user->checkUser();
unset($_POST);
public function checkUser() { //authentication
$ques = "SELECT * FROM `users` WHERE `users`.`login` = '$this->login'";
$get_us = DB::obj()->connect()->query($ques);
$r = $get_us->fetchAll(PDO::FETCH_ASSOC);
if ($r[0]['login'] === $this->login && $r[0]['password'] === $this->password)
{
setcookie('user_id',$r[0]['id'],time()+3600);
setcookie('login',$r[0]['login'],time()+3600);
header("Refresh:1; http://site.loc/index.php");
}
}
Answer the question
In order to leave comments, you need to log in
Try passing the 4th parameter to the setcookie method with the value '/'
The path to the directory on the server from which cookies will be available. If set to '/', cookies will be available in the entire domain. If set to '/foo/', cookies will only be available from the /foo/ directory and all its subdirectories (for example, /foo/bar/) of the domain. The default value is the current directory where the cookie is set.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question