Jump to content

Recommended Posts

Hi I am fairly new to using cookies, therefore I would like some help...

 

I have users that come to my site to fill in a form via specific urls. I.e http://www.site.com/test and http://www.site.com/test2 etc. This will determine who they are associated to. I.e test or test2

Depending on what url they come through I need to set a cookie so that even if they dont come via this url in the future i.e they just go straight to the site through http://www.site.com and then click the form page, I can still associate them from where they came from previously.

 

What would be the best way to set the cookie and then check in the future that one is set?

 

Im guessing to set it would be something like:

$value = "test". (Or "test2" depending on the url)

 setcookie('associate', '$value', time()+86400*365, '/'); #expire in a year

 

And then to retrieve it would be

$_COOKIE['associate']

. Is this correct?

 

Thanks for your help.

Link to comment
https://forums.phpfreaks.com/topic/159055-setting-a-cookie/
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.