P3P header resolves cookie cross-domain problem _javascript Tips

Source: Internet
Author: User
Tags setcookie

P3p

P3P is a standard that is called a personal security platform (the Platform for privary Preferences), protects online privacy so that Internet surfers can choose whether to be collected by third parties and use their own personal information when browsing the Web. If a station does not adhere to the P3P standard, then the cookies will be automatically rejected, and P3P can also be able to automatically break the many kinds of cookies embedded way. P3P is developed by the Global Information Federation Web.

Example

When there is an IFRAME, you want to get the cookie inside the iframe frame, add the P3P header information in the motion page of the IFRAME, or not under IE. Because IE has a security policy, restricting the page does not save Third-party cookies (note: When the previous interview page is a first party cookie, a Third-party cookie is a Web page other than the previous web cookies).

Copy Code code as follows:

<?php
//http://www.a.com/a_setcookie.php file contents:
Setcookie (" Test "," TestVal ", Time () +3600,"/",". a.com ");
//http://www.a.com/a_getcookie.php file contents:
Var_dump ($_cookie);
/*-----------------------------------------------------------------------
Http://www.b.com/b_ setcookie.php file contents:
<iframe src= "http://www.a.com/a_setcookie.php?id=www.b.com" ></iframe>
Access via browser: http://www.b.com/b_setcookie.php
http://www.a.com/a_getcookie.php after accessing the B.Com domain, we did not A.com domain Discovery set the cookie value.
Change the contents of the http://www.a.com/a_setcookie.php file to read as follows:
------------------------------------------------------------ --------------*/
Header (' p3p:cp= "cura ADMa DEVa Psao psdo our bus UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR" ") ;
Setcookie ("Test", "TestVal", Time () +3600, "/", ". a.com");
//re-access: http://www.b.com/b_setcookie.php
//http://www.a.com/a_getcookie.php Set the cookie value for the a.com domain after accessing the B.Com domain.

JS uses P3P protocol

Copy Code code as follows:

Xmlhttp.setrequestheader ("P3P", "cp=" cura ADMa DEVa Psao psdo our bus UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR "' );

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.