tags:

views:

346

answers:

4

Can a parameter of path be added to $_COOKIE[]?

A: 

yes, it's the 4th argument, but you will only be able to access the cookie if it was set using a path that the current directory resides in.

that's confusing... here it is from php:

The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain . If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain . The default value is the current directory that the cookie is being set in.

http://php.net/manual/en/function.setcookie.php

You access it like any other cookie. It will become available in $_COOKIE if the script has access to it.

Galen
I mean how to read it, how to access cookie values in different paths but on the same domain name?
Steven
How to differentiate them?
Steven
php doesn't do that for you. you would have to implement that yourself.
Galen
+1  A: 

In case you are trying to access cookies set for a different path on the same domain than the current, that can't be done. The browser itself restricts this, and only sends the cookies appropriate for the current path.

Jani Hartikainen
A: 

No, such parameters are impossible because the browser does not send the path to the server. It does only send the name and the value of each cookie (so you can't see the path, if it's a session cookie, when it will expires and so on).

Emil Vikström
A: 

I don't think it will be possible to get the cookie from a different path, since it could possibly cause a security issue.

Krishna Shasankar