php怎麼設定p3p頭

藏色散人
發布: 2023-03-12 21:48:01
原創
2549 人瀏覽過

php設定p3p頭的方法:1.編輯HOST,加入「127.0.0.1 www.a.com」;2、建立a_setcookie.php和a_getcookie.php等檔案;3、透過header設定p3p頭即可。

php怎麼設定p3p頭

本文操作環境:windows7系統、PHP7.1版、Dell G3電腦。

php怎麼設定p3p頭?

PHP 透過設定P3P頭來實作跨域存取COOKIE

我的是CentOS的系統(Linux 核心)

#編輯HOST

vi /etc/hosts
登入後複製

加入

127.0.0.1        www.a.com
127.0.0.1        www.b.com
登入後複製

首先:建立a_setcookie.php 文件,內容如下:

<?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"); 
?>
登入後複製

然後:建立a_getcookie.php 文件,內容如下:

<?php 
var_dump($_COOKIE); 
?>
登入後複製

最後:建立b_setcookie.php 文件,內容如下:

<script src="http://www.a.com/a_setcookie.php?id=www.b.com"></script>
登入後複製

————————————————————————————

三個檔案建立完畢後,我們透過瀏覽器依序造訪:

http://www.b.com/b_setcookie.php
http://www.a.com/a_getcookie.php
登入後複製
登入後複製

我們會發現,在造訪b.com網域的時候,我們並沒有在a.com網域設定上cookie值。

然後我們修改一下a_setcookie.php文件,去掉註解符號,a_setcookie.php即為:

<?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");  
?>
登入後複製

再次透過瀏覽器依序存取:

http://www.b.com/b_setcookie.php
http://www.a.com/a_getcookie.php
登入後複製
登入後複製

這次,你會發現在造訪b.com網域的時候,我們設定了a.com網域的cookie值。

末了補充一句,似乎只有IE對跨域存取COOKIE限制比較嚴格,上述程式碼在FIREFOX下測試,即使不發送P3P頭訊息,也能成功。

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

推薦學習:《PHP影片教學

透過Fiddler可以方便的知道上面P3P程式碼的意思###
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
登入後複製

以上是php怎麼設定p3p頭的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
php
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!