Is there any way to update cookies across folders in PHP?
For example, consider the following directory structure:
- A is the parent directory and has two parallel children folders B and
C. - In A, there is a page called a.php.
- In A/B, there is a page called b.php.
- In A/C, there is a page called c.php.
Now, I do the following 3 things:
- setcookie(“num” 1) in a.php
- setcookie(“num” ,10) to update the cookie in b.php
- setcookie(“num” , “”, time()-3600) to clear the cookie in c.php
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.
setcookieaccepts apathargument which will set the path at which the cookie applies. Simply add it to thesetcookiecall, something likesetcookie('num', 1, 3600, '/');A path of
/will mean it’s available for the entire domain.