I'm trying to set path in setcookie for my websites cookie, which contains a string followed by #wall , I could see path only till the first string, it's not accepting the # fraction of the path.
code goes like this:
$wall = array(
$this->database,
$this->response['grouplist'][0],
$this->username
);
setcookie(
"wall",
json_encode($wall),
time() + 3600 * 24 * 1000 ,
"/" + $this->database + "/#wall",
".mywebsite.com",
0
);
session_set_cookie_params(0, '/', '.mywebsite.com');
output :
mywebsite.com /S71c9524b57ab1b3383bcb14478b570b6 2019-07-16T06:37:55.065Z 92
Fragment is not a part of Path
The
#character specifies the fragment part of a URL (RFC 3986):So the fragment (
wall, particularly) is a different part of URL, and is not considered as part of the path:Moreover, fragments depend on the document MIME type and are evaluated by the user agent (RFC 3986, 3.5. Fragment), i.e. fragments are never sent to the server:
In other words, URL fragments are not supposed to work in the cookie
Pathattributes, and the server is not supposed to know anything about fragments.PHP syntax
Also note,
+is an arithmetic operator, so your"/" + $this->database + "/#wall"is evaluated to0. If you meant concatenation, use the.(dot) operator instead:Output
So you should replace your "arithmetic" expression with
"/{$this->database}/#wall".It may work... sometimes
I have tested how the current version of Mozilla Firefox processes cookies for a path with different fragments. As it turns, it actually writes the cookies into
document.cookiefor different fragments, but one has to hard-reload the page in order to update the cookies. So I doubt that this is a useful feature.