whitestreak Posted June 10, 2007 Share Posted June 10, 2007 I set a cookie in http://websitename.com/newd/ like this: setcookie("username", "jason", time()+36000, "/newd/"); I would like to use the cookie value while running a script in http://websitename.com/checkcookie.php and not from http://websitename.com/newd/ echo . $_COOKIE["username"]; which doesn't work because the cookie is set in /newd/ So, how do I specifiy the path that needs to be used to check for the cookie value? I tried variations like: echo . $_COOKIE["/newd/username"]; echo . $_COOKIE["../newd/username"]; etc, but no luck. What's the syntaxt for putting in the path name? Would greatly appreciate any help. I have been breaking my head over this for 2 days. I am a PHP newb. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/55011-solved-syntax-for-cookie-path/ Share on other sites More sharing options...
wildteen88 Posted June 10, 2007 Share Posted June 10, 2007 Leave the cookie path out if you want to be able to access the cookie site wide. You don't need to set the cookie path to where you are setting it. That is not how cookie path works. cookie path works by limiting where the cookie can be accessed from. Quote Link to comment https://forums.phpfreaks.com/topic/55011-solved-syntax-for-cookie-path/#findComment-271949 Share on other sites More sharing options...
whitestreak Posted June 11, 2007 Author Share Posted June 11, 2007 Wildteen, Thanks. I should have mentioned that it is an other application that is setting the cookie, and not my script. That application sets the cookie in a particular location, not site wide. I tried hacking it, but it causes other issues (does work, though). My problem is accessing the cookie. I want to be able to access the cookie while running a script from another folder within the same site. I know that the cookie can be accessed from any folder which is a sub folder of where the cookie is set, but what about a completely different folder? Is there a way to do it? Without hacking the script that creates the cookie? Quote Link to comment https://forums.phpfreaks.com/topic/55011-solved-syntax-for-cookie-path/#findComment-272110 Share on other sites More sharing options...
whitestreak Posted June 11, 2007 Author Share Posted June 11, 2007 I solved this by making changes to the functions that set the cookie and also clear it upon logout. Changed them so that the cookie is set in the main folder /. This way, all subfolders have access to the cookie. I got help from Volka at devnetwork and also looked at a plugin made for making cookie available site-wide. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/55011-solved-syntax-for-cookie-path/#findComment-272344 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.