1
Hello, good night I would very much like someone to ask me a question about cookies in PHP when I set the cookie it usually goes to the browser’s cookie area with the correct date for which I set it, which in this case is an expiration date of 5 years. But when I close the browser the cookie simply disappears as if it never existed. And this happens to any browser I test. Is there anything I can do to fix this?
Follow the part of my code that configures cookies
if(isset($_POST['remember-login']) or $_POST['remember-login']=="1")
{
$time = time()+3600*24*30*12*5;
//echo"<script> alert('".$time."'); </script>";
//session_set_cookie_params($time);
setcookie("token_session", sha1($user['id']), time()+3600*24*30*12*5);
//$token_session = $_COOKIE["token_session"];
$_SESSION['token_session'] = $_COOKIE["token_session"];
$token_session = $_SESSION['token_session'];
echo"<script> window.location.href='redireciona.php' </script>";
}else{
setcookie("token_session", sha1($user['id']));
//$token_session = $_COOKIE["token_session"];
$_SESSION['token_session'] = $_COOKIE["token_session"];
$token_session = $_SESSION['token_session'];
echo"<script> window.location.href='redireciona.php' </script>";
}
This is the kind of problem that can not be reproduced. I tried to reproduce it and could not... This problem happened to me almost 5 years ago, I solved it by doing this:
setcookie("token_session", sha1($user['id']), time()+3600*24*30*12*5, "/");
.... I don’t know if it’ll solve for you...– Andrei Coelho
It seems that solved here man, thank you very brother, I had no idea how it would solve this issue, until I thought it was server problem. Vlw himself
– William De Paula
Quiet... =)
– Andrei Coelho