Home  >  Article  >  Backend Development  >  How to set p3p header in php

How to set p3p header in php

藏色散人
藏色散人Original
2021-09-24 11:08:402571browse

How to set p3p header in php: 1. Edit HOST and add "127.0.0.1 www.a.com"; 2. Create files such as a_setcookie.php and a_getcookie.php; 3. Set p3p header through header That’s it.

How to set p3p header in php

The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

How to set p3p header in php?

PHP implements cross-domain access to COOKIE by setting the P3P header

My system is CentOS (Linux kernel)

Edit HOST

vi /etc/hosts

Join

127.0.0.1        www.a.com
127.0.0.1        www.b.com

First: Create a_setcookie.php file with the following content:

<?php 
//header(&#39;P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"&#39;); 
setcookie("test", $_GET[&#39;id&#39;], time()+3600, "/", ".a.com"); 
?>

Then: Create a_getcookie.php file with the following content:

<?php 
var_dump($_COOKIE); 
?>

Finally: Create the b_setcookie.php file with the following content:

<script src="http://www.a.com/a_setcookie.php?id=www.b.com"></script>

----------------------------

After the three files are created, we access them one by one through the browser:

http://www.b.com/b_setcookie.php
http://www.a.com/a_getcookie.php

We will find that when accessing the b.com domain, we do not set the cookie value in the a.com domain.

Then we modify the a_setcookie.php file and remove the comment symbols. a_setcookie.php is:

<?php  
header(&#39;P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"&#39;);  
setcookie("test", $_GET[&#39;id&#39;], time()+3600, "/", ".a.com");  
?>

Visit it again through the browser:

http://www.b.com/b_setcookie.php
http://www.a.com/a_getcookie.php

This time, you You will find that when accessing the b.com domain, we set the cookie value of the a.com domain.

Finally, it seems that only IE has stricter restrictions on cross-domain access to COOKIE. The above code was tested under FIREFOX and it can be successful even without sending P3P header information.

==========================================

Recommended learning: "PHP Video Tutorial"

You can easily know the meaning of the above P3P code through Fiddler

P3P Header is present:
CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"
Compact Policy token is present. A trailing &#39;o&#39; means opt-out, a trailing &#39;i&#39; means opt-in.
CURa
Information is used to complete the activity for which it was provided.
ADMa
Information may be used for the technical support of the Web site and its computer system.
DEVa
Information may be used to enhance, evaluate, or otherwise review the site, service, product, or market.
PSAo
Information may be used to create or build a record of a particular individual or computer that is tied to a pseudonymous identifier, without tying identified data (such as name, address, phone number, or email address) to the record. This profile will be used to determine the habits, interests, or other characteristics of individuals for purpose of research, analysis and reporting, but it will not be used to attempt to identify specific individuals. 
PSDo
Information may be used to create or build a record of a particular individual or computer that is tied to a pseudonymous identifier, without tying identified data (such as name, address, phone number, or email address) to the record. This profile will be used to determine the habits, interests, or other characteristics of individuals to make a decision that directly affects that individual, but it will not be used to attempt to identify specific individuals.
OUR
We share information with ourselves and/or entities acting as our agents or entities for whom we are acting as an agent.
BUS
Info is retained under a service provider&#39;s stated business practices. Sites MUST have a retention policy that establishes a destruction time table. The retention policy MUST be included in or linked from the site&#39;s human-readable privacy policy.
UNI
Non-financial identifiers, excluding government-issued identifiers, issued for purposes of consistently identifying or recognizing the individual. These include identifiers issued by a Web site or service.
PUR
Information actively generated by the purchase of a product or service, including information about the method of payment.
INT
Data actively generated from or reflecting explicit interactions with a service provider through its site -- such as queries to a search engine, or logs of account activity.
DEM
Data about an individual&#39;s characteristics -- such as gender, age, and income.
STA
Mechanisms for maintaining a stateful session with a user or automatically recognizing users who have visited a particular site or accessed particular content previously -- such as HTTP cookies.
PRE
Data about an individual&#39;s likes and dislikes -- such as favorite color or musical tastes.
COM
Information about the computer system that the individual is using to access the network -- such as the IP number, domain name, browser type or operating system.
NAV
Data passively generated by browsing the Web site -- such as which pages are visited, and how long users stay on each page.
OTC
Other types of data not captured by the above definitions.
NOI
Web Site does not collected identified data.
DSP
The privacy policy contains DISPUTES elements.
COR
Errors or wrongful actions arising in connection with the privacy policy will be remedied by the service.
Validate at: http://www.w3.org/P3P/validator.html
Learn more at: http://www.fiddlertool.com/redir/?id=p3pinfo

The above is the detailed content of How to set p3p header in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn