I don't know if it has been asked before, but I don't know what to search for this issue. I have a page with a form and an AJAX request. The PHP code check in asynchronous if the user exists and it set a cookie when the user ask for an automatic access. The cookie is setted, the code seems to work well. If I try to read the cookie content in the same page with the login form (after a refresh, this is normal - I know), I can see it. But when I try to read the same cookie content from another page, the cookie doesn't exist. It's like if it's not setted. How is this possible?
To make a test I also deactivated the JS redirect once the jquery script receive a success response, but it doesn't fix the issue.
PHP that runs with the jquery.ajax request (it shows me the right text):
setcookie("access", $string, time()+31536000);
if(isset($_COOKIE['access'])) echo "Cookie exists.<br>";
echo "Cookie content: ".$_COOKIE['access'];
connection.php called in other web site pages (the cookie seems to be empty or inexistent):
require_once("connection.php");
if(isset($_COOKIE["access"]))
{
echo "I'm in!<br>";
echo "Cookie content: ".$_COOKIE['access'];
}
source https://stackoverflow.com/questions/67754175/i-can-see-cookie-content-only-in-the-page-has-setted-it-why
No comments:
Post a Comment