How can I obtain the same cookie value for different pages of a website that are not associated with each other? -Php Tutorial

Source: Internet
Author: User
How can I obtain the same cookie value for different pages of a website that are not associated with each other? For example, a website has several unrelated pages in the same directory: 1.php, 2.php, and 3.php.
A user accesses 1. php and generates a cookie:


Setcookie ('mycookie1', $ c1 );
Setcookie ('mycookie2', $ c2 );
Setcookie ('mycookie3', $ c3 );



If the user clicks a hyperlink from another website to enter 2.php, the cookie value set in 1.php cannot be read in 2.php.
If I create a hyperlink in 1. php to connect to 3.php and access 3.php from 1. php, the cookie value set in 1. php will be displayed on 3. php:
2. php and 3. php have the same code:

$ C0 = $ _ COOKIE ['mycookie1'];
$ Cc2 = $ _ COOKIE ['mycookie2'];
$ Cc3 = $ _ COOKIE ['mycookie3'];
Echo $ PC3;
Echo $ cc2;
Echo $ cc3;



How can I read the cookie value set in 1.php on the 3. php page that is fully associated with 1.php?


Reply to discussion (solution)

Set the expiration time of cookie variables

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.