dc_jt Posted May 21, 2009 Share Posted May 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/159055-setting-a-cookie/ Share on other sites More sharing options...
JonnoTheDev Posted May 21, 2009 Share Posted May 21, 2009 Yes, only you do not enclose variables in single quotes as function parameters '$value' should be just $value Quote Link to comment https://forums.phpfreaks.com/topic/159055-setting-a-cookie/#findComment-838847 Share on other sites More sharing options...
dc_jt Posted May 21, 2009 Author Share Posted May 21, 2009 Yes, only you do not enclose variables in single quotes as function parameters '$value' should be just $value Oh yes, sorry that was just a typo. Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/159055-setting-a-cookie/#findComment-838880 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.