Click to See Complete Forum and Search --> : How to restrict a cookie to a directory


albegago
10-17-2003, 02:27 AM
I have a website with a root directory and inside it two directories more.

In the root directory I set a cookie.

I use the info of this cookie on the files located at root directory.

I want to restrict this cookie to the files located at root directory only.

I dont want to the files located into the two directories inside te root directory can access or use this cookie info.


How can I restrict the cookie to just the root directory, to avoid the children directorys to have acces to it?

Khalid Ali
10-17-2003, 04:49 AM
if you set the domain parameter when you write a cookie,I am sure you can achieve that.

albegago
10-19-2003, 10:55 PM
I have the following directoryes structure:


/root/
----/directory1/
----/directory2/

I want a cookie that just work on the files in the root directory.

Thes cookie would not work on the subdirectories.

The theorie says:



"By default, a cookie can be read only by HTML pages that sit on the same Web server and in the same directory as the page that set the cookie.

The "path" sets the top level directory from which a cookie can be read. Set the path of a cookie to the top-level directory of your Web pages, and the cookie is readable by all your Web pages.

Do this by adding path=/; to your cookie. If you just wanted the cookie readable solely in the "food" directory, you'd add path=/food; to your cookie. "


So, you can define in wich DIRECTORIES the cookie WIIL WORK....

But you cant define in wich DIRECTORIES the cookie WONT work...


Furthermore If you say: this cookie will work in the root directory, automatically this cookie will work in all the SUBDIRECTORIES.