Answer the question
In order to leave comments, you need to log in
Why are cookies deleted after re-entering the page?
I send cookies and initiate the session.
<?php
session_start();
if(!isset($user)){
$s = file_get_contents('http://ulogin.ru/token.php?token=' . $_POST['token'] . '&host=' . $_SERVER['HTTP_HOST']);
$user = json_decode($s, true);
}
if(isset($user)){
$first_name = $user['first_name'];
$last_name = $user['last_name'];
$network = $user['network'];
$identity = $user['identity'];
$page_adress = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$_SESSION['user']=$user;
$_SESSION['page_adress'] = $page_adress;
$life_time = time()+(60 * 60 * 24 * 7);
$access_path = "/";
$access_domain = "domain.com";
setcookie('first_name', $first_name, $life_time, $access_path, $access_domain);
setcookie('last_name', $last_name, $life_time, $access_path, $access_domain);
setcookie('network', $network, $life_time, $access_path, $access_domain);
setcookie('identity', $identity, $life_time, $access_path, $access_domain);
setcookie('page_adress', $page_adress, $life_time, $access_path, $access_domain);
}
?>
$boolCheckCookie = false;
$pageAdressCheck = false;
if(isset($_COOKIE['first_name'])){
$username['first_name'] = $_COOKIE['first_name'];
$username['last_name'] = $_COOKIE['last_name'];
$username['network'] = $_COOKIE['network'];
$username['identity'] = $_COOKIE['identity'];
$page_adress = $_COOKIE['page_adress'];
$boolCheckCookie = true;
echo "Отработали куки <br>";
}
else{
if($boolCheckCookie == false){
session_start();
if(isset($_SESSION['user'], $_SESSION['page_adress'])){
$username = $_SESSION['user'];
$page_adress = $_SESSION['page_adress'];
echo "Отработала сессия <br>";
}
}
}
Answer the question
In order to leave comments, you need to log in
At you at each call of the top code cookies are redefined.
if(!isset($user)) always returns True in your case.
I also hope you change the domain name in the code to your own. And if you use a subdomain or www, then put a dot before the domain.
Tried for all files at the very beginning to include session_start ()? Maybe PHP forgets to set cookies in the second file if session_start fails
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question