Fragment is not a part of Path
The #
character specifies the fragment part of a URL (RFC 3986):
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
hier-part = "//" authority path-abempty
/ path-absolute
/ path-rootless
/ path-empty
So the fragment (wall
, particularly) is a different part of URL, and is not considered as part of the path:
The path is terminated by the first question mark ("?") or number sign
("#") character, or by the end of the URI.
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:
...the fragment identifier is not used in the scheme-specific
processing of a URI; instead, the fragment identifier is separated
from the rest of the URI prior to a dereference, and thus the
identifying information within the fragment itself is dereferenced
solely by the user agent...
In other words, URL fragments are not supposed to work in the cookie Path
attributes, 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 to 0
. If you meant concatenation, use the .
(dot) operator instead:
$s = 'abc';
echo "/" + $s + "/#wall", PHP_EOL;
echo "/" . $s . "/#wall", PHP_EOL;
echo "/{$s}/#wall", PHP_EOL;
Output
0
/abc/#wall
/abc/#wall
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.cookie
for 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.