I am setting two cookies in PHP in my root directory
setcookie ("st", "$todays_system_date" ); setcookie ("en", "$tomorrow" );
My problem is I need to set them again in a script that is in a deeper folder eg: /diary/
When I do set them and then try to read them or look at the cookies set , I find I have 2x en and 2x st cookies .
My question is how can I make reference to just one set of cookies ? and read them ?
thanks in advance
Cookies are key/value pairs – they will only ever have a single value in any given scope.
However:
For example, if you set the cookie
stin the root (/) with the value1, and in/diary/with value2, the two cookies will exist in their own right. When you are in the/directory (or any subdirectory of/that is not/diary/or a subdirectory of/diary/) the value will be1. When you are in/diary/or a subdirectory of/diary/if will be2:For example:
If you look at the HTTP response message that is sent by PHP you will see 2
Set-Cookie:headers for the keyst. However, on the next request within the cookie’s scope, only the later value2will be sent back to the server.