PHP 通过设置P3P头来实现跨域访问COOKIE

PHP 通过设置P3P头来实现跨域访问COOKIE,第1张

概述CentOS的系统(Linux 内核) 编辑HOST vi /etc/hosts 加入127.0.0.1 www.a.com127.0.0.1 www.b.com 首先:创建 a_setcookie.

 

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('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");
?>

然后:创建 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('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');

setcookie("test",".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头信息,也能成功。

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

通过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 '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,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.


ValIDate at: http://www.w3.org/P3P/valIDator.HTML
Learn more at: http://www.fiddlertool.com/redir/?ID=p3pinfo

参考文档:http://www.w3.org/P3P/

总结

以上是内存溢出为你收集整理的PHP 通过设置P3P头来实现跨域访问COOKIE全部内容,希望文章能够帮你解决PHP 通过设置P3P头来实现跨域访问COOKIE所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1027244.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存