Reputation: 183599
I have a WordPress site where we're tracking users with cookies unique to the session. I have the following code in my functions.php file:
if (!session_id())
session_start();
// session user id:
if (isset($_COOKIE["my_user_id"])) {
$my_user_id = $_COOKIE["my_user_id"];
}
else {
$my_user_id = uniqid();
setcookie("my_user_id", $my_user_id);
}
And on each page:
echo $_COOKIE["my_user_id"];
I would expect this to show the same user ID on each page when I was clicking around- however, the user ID is changing for different pages, though it remains the same throughout multiple clicks on the same page. Wouldn't a cookie value be site wide?
Upvotes: 2
Views: 3309