The p3p protocol is used to implement cross-domain set cookie, and the session transfer failure problem in the IFRAME of the same domain is solved.

Source: Internet
Author: User
Tags set cookie

This problem occurs in previous projects to implement cross-server communication. although Mr. Jane told me about the principle of pass before, because no actual operation has been performed, and he is not sure how to implement the pass. I searched for information online and found the p3p Protocol. Its definition is:

P3p is a privacy protection recommendation standard published by the World Wide Web Consortium (W3C). It aims to provide privacy protection for Internet users who surf the Internet. More and more Websites collect user information when consumers access the website. The purpose of making the p3p standard is to alleviate consumers' concerns about potential infringement of privacy due to website collection of personal information. The concept of the p3p standard is: the privacy policy of a Web site should inform the visitor of the type of information collected by the site, who the information will be provided to, how long the information will be retained, and how the information will be used, for example, the website shall make a statement such as "this website will monitor the pages you visit to improve the site usage" or "this website will provide you with more suitable advertisements as much as possible. Users who access the website that supports p3p have the right to view the site privacy report and decide whether to accept cookies or use the website.

Finally, I decided to use cross-domain cookie settings to achieve this requirement.

First, assume that there are Station A (www.aaa.com) and Station B (www.bbb.com). If the two sites are on different servers and in different domains, create a setcookie. php file under Station A. The Code is as follows:

<? PHP

Header ('p3p: Cp = "Cura ADMA Deva psao psdo our bus uni pur int DEM sta pre com nav OTC Noi DSP cor "');

$ Cookie_name = $ _ Get ['name'];

$ Cookie_value = $ _ Get ['value'];

Setcookie ($ cookie_name, $ cookie_value, time () + 3600 );

?>

Next, create a file named B _setcookie.php on Site B. The Code is as follows:

<? PHP

<SCRIPT src = "http://www.aaa.com/setcookie.php? Name = Test & value = bbb.com "> </SCRIPT>

?>

Now, we create another file named getcookie. php under Site A. The Code is as follows:

<? PHP

Echo '<PRE> ';

Print_r ($ _ cookie );

?>

Now we first access the B _setcookie.php file on Site B in the browser, and then visit the getcookie. php file on Site A to see if the corresponding cookie value is printed.

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.