Reputation: 1177
I have one server but two directories for example:
- www
- Directory1
- index.php
- page1.php
- page2.php
- Directory2
- index.php
- page3.php
- page4.php
When I want to transfer from the page index.php
of Directory1
to the page index.php
of Directory2
, how can I pass the cookies set in the page index.php
of Directory1
using PHP?
Upvotes: 0
Views: 2573
Reputation: 3073
Just don't set the optional Path parameter, and then it is available to both directories.
Upvotes: 0
Reputation: 25763
according to PHP documentation
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.
$time = time() + 3600;
setcookie('foo', 'bar', $time, "/");
when you set the fourth parameter i.e path
as /
, it will be accessible to you on the domain level, and i guess that is what you need.
Upvotes: 1
Reputation: 11487
Use the path
parameter:
setcookie("name", "value", time() + 3600, "/");
Upvotes: 2