Jump to content

Recommended Posts

I have the following code

 

if(!isset($_COOKIE['TOS']))
{
$expire = time() + 60*60*24*31*12*5;
setcookie('TOS', 'No', $expire);
}

$TOS = $_COOKIE['TOS'];

 

And on successful login, I have

 

$expire = time() + 60*60*24*31*5;
setcookie('TOS', 'Yes', $expire);

 

Now, $TOS determines whether or not the Checkbox for "I accept the TOS" is checked on page load or not. I can login and logout and the checkbox will still be ticked. I can login, logout and close the tab and the checkbox will still be ticked. But once I close the browser, when I open it again the checkbox is unticked.

 

Any idea what can be wrong?

Does closing the browser and visiting the page again also include using a different URL from the URL that was used when the cookie was set, such as one that has a www. on it or no-www. on it or is using a different path to the file?

 

You are not specifying the path or domain parameters in the setcookie() so the cookie will only match the exact hostname/subdomain (www. is a hostname/subdomain) and path where the cookie was set at.

We only see the information you supply in your posts. If you post code that shows you are setting a value right before you use it, we must assume that is your actual code or you would not have posted it together  :psychic:  -

 

$expire = time() + 60*60*24*31*5;
setcookie('TOS', 'Yes', $expire);

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.