Jump to content

[SOLVED] Syntax for COOKIE path


whitestreak

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/55011-solved-syntax-for-cookie-path/
Share on other sites

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.

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?

 

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.

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.