Jump to content

Setting a cookie


dc_jt

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.