COOKIE in PHP5.5.9

Source: Internet
Author: User
I created four files under localhost {code ...} the code in the file is the same {code ...} I thought that after all the pages are opened, refresh them repeatedly until all the cookies are set up, and the results should be the same. But actually not {code...} clearly shows that php's $ __cookie... I created four files under localhost.

/1.php/a/1.php/test/1.php/test/a/1.php

The code in the file is the same


  

I thought that after all the pages are opened, refresh them repeatedly until all the cookies are set up, and the results should be the same.
But not actually

/1.php array(1) { ["/var/www/html"]=> string(13) "/var/www/html" } /a/1.php array(2) { ["/var/www/html/a"]=> string(15) "/var/www/html/a" ["/var/www/html"]=> string(13) "/var/www/html" } /test/1.php array(2) { ["/var/www/html/test"]=> string(18) "/var/www/html/test" ["/var/www/html"]=> string(13) "/var/www/html" } /test/a/1.php array(3) { ["/var/www/html/test/a"]=> string(20) "/var/www/html/test/a" ["/var/www/html/test"]=> string(18) "/var/www/html/test" ["/var/www/html"]=> string(13) "/var/www/html" } 

It is obvious that the COOKIE obtained by php $ __cookie is the cookie set in the range from the file level to the root directory. The cookies set for files in deeper layers and files in different directories cannot be obtained.
I want to ask
Assume that the/test/1.php file needs to obtain the cookie set in the/test/a/1.php file. How can this problem be achieved?
What is the principle of this phenomenon?

Reply content:

I created four files under localhost.

/1.php/a/1.php/test/1.php/test/a/1.php

The code in the file is the same


   

I thought that after all the pages are opened, refresh them repeatedly until all the cookies are set up, and the results should be the same.
But not actually

/1.php array(1) { ["/var/www/html"]=> string(13) "/var/www/html" } /a/1.php array(2) { ["/var/www/html/a"]=> string(15) "/var/www/html/a" ["/var/www/html"]=> string(13) "/var/www/html" } /test/1.php array(2) { ["/var/www/html/test"]=> string(18) "/var/www/html/test" ["/var/www/html"]=> string(13) "/var/www/html" } /test/a/1.php array(3) { ["/var/www/html/test/a"]=> string(20) "/var/www/html/test/a" ["/var/www/html/test"]=> string(18) "/var/www/html/test" ["/var/www/html"]=> string(13) "/var/www/html" } 

It is obvious that the COOKIE obtained by php $ __cookie is the cookie set in the range from the file level to the root directory. The cookies set for files in deeper layers and files in different directories cannot be obtained.
I want to ask
Assume that the/test/1.php file needs to obtain the cookie set in the/test/a/1.php file. How can this problem be achieved?
What is the principle of this phenomenon?

Go to the setcookie documentation.
The third parameter path of setcookie can define the directory in which the cookie takes effect. Setting path to/indicates that the cookie can be shared under the domain name.

This prevents cookie variable conflicts and is more secure.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.