I am wrestling with an old script I am updating for someone. It stores an id in a cookie on login, then reads it back when loading pages to return the right userdata. Later on I will change it to use sessions, but for now I want this to work...
The problem is that the cookie does get set to the right value (I check it in developer tools), but when I request the value through $_COOKIE['id'] it always returns '1'.
Anybody has an idea why this is happening?
Code: setting the cookie is in '/modules/users/login.php'
setcookie("id", $row['id'], time()+$_POST['tijdingelogd'],'/');
EDIT: ADDED INFORMATION After setting the cookie values, the visitor gets redirected using:
header("location:/index.php");
Reading the cookie is in '/connection/functions.php
echo $_COOKIE['id'];
I found my answer, during the check whether a visitor was logged in, the value for the cookie was reset to 1 within the script. This was not reflected in the developer tools, hence my confusion.
For future visitors coming to this thread, the code setting the value without it reflecting in developer tools was:
$_COOKIE['userid'] = 1;
Thanks to all answering to this thread