我的是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", $_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值。

末了补充一句,似乎只有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, 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.

Validate at: http://www.w3.org/P3P/validator.html
Learn more at: http://www.fiddlertool.com/redir/?id=p3pinfo

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

转载于:https://www.cnblogs.com/jackluo/archive/2013/03/03/2941393.html

PHP 通过设置P3P头来实现跨域访问COOKIE相关推荐

  1. 转载 - 通过设置P3P头来实现跨域访问COOKIE

    作者:老王 网上看了别人介绍的一片文章,说使用P3P可以完成跨域COOKIE操作,感觉很COOL,不过没有提供源代码,我胡乱写了一下,大家看看. 实际工作中,类似这样的要求很多,比如说,我们有两个域名 ...

  2. CP=CAO PSA OUR 用P3P header解决iframe跨域访问cookie

    短信模块以iframe方式嵌入系统,系统登录时,短信登录失败,这种情况只在win7下IE出现,win10未出现. 原因:IE禁止iframe跨域访问cookie 解决方案: 在短信登录时,进行如下设置 ...

  3. p3p-header解决跨域访问cookie

    P3P header允许跨域访问隐私数据,从而可以跨域set-cookie成功 header("P3P: CP=CURa ADMa DEVa PSAo PSDo OUR BUS UNI PU ...

  4. ajxs跨域 php_php设置header头允许ajax跨域请求

    在做项目的时候,我们有时候希望能够可以跨域进行请求,但是ajax访问php接口的时候,通常会报一个错误: Failed to load 你的网址/test.php: No 'Access-Contro ...

  5. Web应用跨域访问解决方案

    Web应用跨域访问解决方案 Web应用的跨域访问解决方案 Web跨域访问解决方案 做过跨越多个网站的Ajax开发的朋友都知道,如果在A网站中,我们希望使用Ajax来获得B网站中的特定内容,如果A网站与 ...

  6. Web应用跨域访问及单点登录解决方案汇总

    做过跨越多个网站的Ajax开发的朋友都知道,如果在A网站中,我们希望使用Ajax来获得B网站中的特定内容,如果A网站与B网站不在同一个域中,那么就出现了跨域访问问题.Ajax的跨域访问问题是现有的Aj ...

  7. html的页面怎样直接跨域访问,【HTML】iframe跨域访问问题

    概述 本地同一浏览器访问本地HTML文件和访问服务器端HTML文件,本地Iframe没有自适应高度,而服务器端的Ifrane自适应了高度. 1.问题重现: Chrome 版本 41.0.2272.10 ...

  8. 阿里云OSS设置跨域访问

    阿里云OSS设置跨域访问 简介 操作步骤 简介 OSS 提供 HTML5 协议中的跨域资源共享 CORS 设置,帮助您实现跨域访问.当 OSS 收到一个跨域请求(或者 OPTIONS 请求)时,会读取 ...

  9. Spring Boot配置跨域访问策略

    From: https://blog.csdn.net/garyond/article/details/80192760 1. 引言 我们在开发过程中通常因为不同应用之间的接口调用或者应用之间接口集成 ...

最新文章

  1. php5.3.28安装,安装php-5.3.28 时问题
  2. 【错误记录】Mac 中 IntelliJ IDEA 运行 Python 程序报错 ( “Python“ 因为出现问题而无法打开 )
  3. python numpy 奇数偶数行互换_python 列表推导式(经典代码)(21)
  4. 华硕P8B-C/2L及其他
  5. python(1) - 数据类型和变量
  6. 限制按钮点击_Android | 使用 AspectJ 限制按钮快速点击
  7. 全国计算机等级考试二级Python考试大纲预测和分析
  8. phoneGap实现离线缓存
  9. 为什么自动挡的挡位顺序都是P、R、N、D?
  10. 2018.12.26 作业
  11. Java fluent风格
  12. 看《乡村爱情》,秒懂区块链!
  13. 一起谈.NET技术,ASP.NET的状态管理
  14. LinkedIn开源数据发现和管理工具 WhereHows
  15. linux多拨脚本,openwrt-mwan3负载均衡,多线多拨
  16. Daz导出模型的部件中英文对照
  17. Problem:跳房子
  18. 3dmax2014植树插件_3DsMax种树插件:ForestPack Pro v6.1.2 For 2015-2019 updated Libraries
  19. 苹果耳机airpods2需要激活?_苹果耳机三兄弟,谁才是安卓手机的绝配?
  20. mysql无法执行二进制文件_kail系统64,mysql64,出现-bash: bin/mysqld: 无法执行二进制文...

热门文章

  1. [react] 写例子说明React如何在JSX中实现for循环
  2. [react] React必须使用JSX吗?
  3. 前端-给定一个字符串str,如何实现每个单词首字母都大写,其余部分小写。
  4. [html] 如何给页面添加追加右键菜单(原右键菜单功能保持不变)
  5. [html] 在HTML5中,用于获得用户的当前位置是哪个方法?
  6. [html] 移动端如何让页面强制横屏显示?
  7. 前端学习(2753):创建新页面和页面配置
  8. 工作170:删除做个判断操作 成功删除 取消取消
  9. 前端学习(2053)vue之电商管理系统电商系统之使用pm2管理
  10. 前端学习(1534):服务器和客户端传输