PHP利用P3P實現跨域

來源:互聯網
上載者:User

標籤:service   javascrip   use   exp   web   element   trail   sdn   --   

有別於js跨域、IFRAME跨域等的常用處理辦法,還可以利用P3P來實現跨域。

P3P是什麼

P3P(Platform for Privacy Preferences)是W3C公布的一項隱私保護推薦標準,以為使用者提供隱私保護。

P3P標準的構想是:Web 網站的隱私權原則應該告之訪問者該網站所收集的資訊類型、資訊將提供給哪些人、資訊將被保留多少時間及其使用資訊的方式,如網站應做諸如 “本網站將監測您所訪問的頁面以提高網站的使用率”或“本網站將儘可能為您提供更合適的廣告”等申明。訪問支援P3P網站的使用者有權查看網站隱私報告,然 後決定是否接受cookie 或是否使用該網站。

如何利用P3P實現跨域

在開發中,我們碰到的跨域主要還是糾結在IE,頁面中的IFRAME或者FRAME或者JS跨域的時候,IE有安全性原則限制頁面不帶cookie,但是如果我們加上P3P,就沒有這策略的限制。這也是P3P來突破跨域的可行前提。

以下為摘錄的例子:

http://www.a.com/a_setcookie.php 檔案內容:
<?php setcookie("test", $_GET[‘id‘], time()+3600, "/", ".a.com"); ?>
http://www.a.com/a_getcookie.php 檔案內容:
<?php var_dump($_COOKIE); ?>
http://www.b.com/b_setcookie.php 檔案內容:
<script src="http://www.a.com/a_setcookie.php?id=www.b.com"></script>
通過瀏覽器訪問:
1?> http://www.b.com/b_setcookie.php
2?> http://www.a.com/a_getcookie.php
訪問1 b.com域後,我們並沒有在2 a.com域發現設定上cookie值。

將http://www.a.com/a_setcookie.php檔案內容改為如下:
<?php  
header(‘P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"‘);   
setcookie("test", $_GET[‘id‘], time()+3600, "/", ".a.com");  
?>
再次訪問:
http://www.b.com/b_setcookie.php
http://www.a.com/a_getcookie.php
在訪問b.com域後,設定了a.com域的cookie值。

從上面例子可以看出通過發送P3P頭資訊而實現的跨域。(在Firefox不發送P3P也能跨域成功)

PHP使用P3P協議

header( ‘P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"‘ );

JS使用P3P協議

xmlhttp.setRequestHeader( "P3P" ‘CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"‘ );

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 ‘o‘ means opt-out, a trailing ‘i‘ 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‘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‘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‘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‘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.

PS,這裡說的跨域主要是設定cookie的情況,如果是跨域讀取cookie,要保證在對應設定cookie的時候設定了P3P,否則在讀取的事情IE會屏蔽跨域cookie。

 

From:http://blog.163.com/[email protected]/blog/static/3743091520122733733736/

PHP利用P3P實現跨域

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.