I'm confused as to why this is working;
setcookie("user", $user_id, time()+604800);
session_start();
$_SESSION['user_id'] = "string";
Even though setcookie()
contains no reference to $_SESSION['user_id']
, when I echo $_SESSION['user_id']
from another page with the code:
session_start();
echo $_SESSION['user_id'];
It prints string
.
I was under the impression that setcookie()
had to reference a $_SESSION
key in order for it to be called from any page?
Perhaps I'm well off base, but I just want to make sure I understand why this is working before I implement it, as I'd rather it not fault because of incorrect usage.
Any help, comments, advice and explanations will be appreciated!