Jump to content

Php Cookies Not working throughout Domain


Joesavage

Recommended Posts

I am trying to use  a cookie to tell when someone has already been to my website. Right now the problem is that if the cookie gets set on one page, it does not get read by other pages.

$Affcookie = 0;
$Affcookie = $_COOKIE["track"];
if ($Affcookie == 0)
{
$Cookvar = 1;
$Expire = time() + 60*60*24*60;
setcookie("track", 1, $Expire);
}
if ($Cookvar == 1;)
{
echo 'blah';
}

Right now if I go to a page on my domain it first echoes 'blah' and then if i refresh then it doesnt echo, which is correct. But if I go to any other page on my domain then once again 'blah' is echoed. All pages have this is same piece of code on them. So they all check to see if the cookie[track] = 1.

Link to comment
Share on other sites

Try this:

 

$Affcookie = 0;
$Affcookie = $_COOKIE["track"];
if ($Affcookie == 0)
{
$Cookvar = 1;
$Expire = time() + 60*60*24*60;
setcookie("track", 1, $Expire, "/");
}
if ($Cookvar == 1;)
{
echo 'blah';
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.