Fischer
Fischer

Reputation: 125

How to update cookies across directories in PHP?

Is there any way to update cookies across folders in PHP?
For example, consider the following directory structure:

Now, I do the following 3 things:

But, in my test run, because b.php and c.php are not in the same directory level as a.php, I can't update the cookie in b.php and c.php. The only thing I can do in b.php and c.php is read the cookie.
I only can update cookie in pages which are also in A.

However, in the real cases it is common to store different pages in the different folders.

Do we must update cookies in the pages which has the same directory level as that in which the cookie is originally set?

My php version : 5.2.6

If there is any further information I can provide in order to better describe the problem, please let me know!
Thank you.

Upvotes: 3

Views: 897

Answers (1)

Tom van der Woerdt
Tom van der Woerdt

Reputation: 29975

setcookie accepts a path argument which will set the path at which the cookie applies. Simply add it to the setcookie call, something like setcookie('num', 1, 3600, '/');

A path of / will mean it's available for the entire domain.

Upvotes: 3

Related Questions