Search code examples
phpcookiessetting

Php cookie not setting


Alright I'm totally baffled.

Here's my code:

if ($password == $correct_password[0] && !isset($_COOKIE['user'])) {
            setcookie("user", $email, time() + 3600);
            var_dump(isset($_COOKIE['user']));
            echo "!";
        }

So it's doing the var_dumps, meaning that the setcookie should called. But the line right after it (checking if it's set) says it's not set!

If anyone could point out the problem it'd be greatly appreciated. Thanks


Solution

  • Still didn't find a solid valid answer, but after endless hours of testing it seems like something with the time. If I set the expiration date too close to the real time, maybe it doesn't register or something. It seemed to work when I set the time further, but I'm taking a break before heavy testing again. Thanks