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('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

以上就是php怎么设置p3p头的详细内容,更多请关注编程界其它相关文章!

--结束END--

本文标题: php怎么设置p3p头

本文链接: https://www.lsjlt.com/news/142.html (转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢

  • php怎么设置p3p头

    php设置p3p头的方法:1、编辑HOST,加入“127.0.0.1 www.a.com”;2、创建a_setcookie.php和a_getcookie.php等文件;3、通过header设置p3p头即可。
    阅读数:696 php
  • php的第一个p是啥意思

    php的第一个p指的是Personal,因为PHP原本的英文全称为Personal Home Page,是“拉斯姆斯·勒多夫”为了要维护个人网页,而用C语言开发的一些CGI工具程序集,来取代原先使用的Perl程序。
    阅读数:612 php
  • php如何只抓取网页头

    php只抓取网页头的方法:1、使用get_headers()函数;2、使用http_response_header方法;3、使用stream_get_meta_data()函数;4、使用php CURL来获取网页头即可。
    阅读数:335 php
  • php 怎么设置空格

    php设置空格的方法:1、创建一个PHP示例文件;2、通过“function white_space( $string, $whitespace ){...}”方法设置空格即可。
    阅读数:113 php 空格
  • php怎么设置星期

    php设置星期的方法:1、通过“date("w");”方法获取数字星期;2、通过“$weekarray[date("w")];”方法获取中文星期;3、通过“date("w",strtotime("..."))”方法获取指定日期。
    阅读数:601 php
  • php 怎么设置本地时间

    php设置本地时间的方法:1、在页头使用“date_default_timezone_set()”设置默认时区为北京时间;2、在php.ini中设置“date.timezone”的值为PRC即可。
    阅读数:270 php
  • php 怎么设置input只读

    php设置input只读的方法:1、打开相应的代码文件;2、通过“<input type="text" readonly>”方式设置input只读即可。
    阅读数:803 php input 只读属性
  • php curl怎么设置cookie

    php curl设置cookie的方法:1、创建PHP示例文件;2、通过curl_setopt函数设置cURL传输选项;3、在CURL中传递cookie即可。
    阅读数:655 php curl cookie
  • php怎么设置oracle编码

    php设置oracle编码的方法:1、获取oracle的字符集;2、运行“select * from V$NLS_PARAMETERS;”;3、通过iconv函数进行编码转换即可。
    阅读数:773 php oracle
  • php怎么设置警告等级

    php设置警告等级的方法:1、在php.ini里修改error_reporting选项;2、在php页面里用error_reporting()函数来修改报错级别。
    阅读数:937 php
  • php怎么设置变量类型

    php中,可利用settype()函数来设置变量类型,语法“settype($var,"数据类型")”;数据类型值可为“boolean”、“integer”、“float”、“string”、“array”、“object”、“null”。
    阅读数:853 php 变量类型
  • php中怎么设置时区

    今天就跟大家聊聊有关php中怎么设置时区,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。PHP中设置时区方法小结代码如下:? date_default_timezone_set(PR
    阅读数:727 php
  • php 脚本怎么设置不超时

    php脚本设置不超时的方法:1、在php.ini里面设置“max_execution_time = 120;”;2、通过PHP的ini_set函数设置“ini_set("max_execution_time", "120");”等等。
    阅读数:537 php
  • php怎么设置并发连接数

    php设置并发连接数的方法:1、找到php-fpm.conf配置;2、编辑选项【pm= static】、【request_terminate_timeout】、【pm.max_requests】。
    阅读数:616 php 并发 连接数
  • php怎么查看文件的权限设置

    在php中,可以利用fileperms()函数来查看文件的权限设置,该函数的作用就是获取并返回文件或目录的权限,语法“fileperms(filename)”;如果获取成功,则会以数字形式返回文件的权限设置。
    阅读数:594 php 文件 权限
  • php pdo怎么设置utf8

    php pdo设置utf8的方法:1、打开相应的PHP代码文件;2、通过“$this->pdo->prepare("set names utf8");”设置utf8编码即可。
    阅读数:259 php pdo tf8
  • php中怎么设置字符集

    在php中,可以使用header()函数来设置字符集,只需要在php文件头部添加“header('Content-type:text/html;charset=字符编码');”代码即可。
    阅读数:668 php 字符集
  • php5.4怎么设置时区

    php5.4设置时区的方法:1、找到并打开php.ini文件;2、查找“date.timezone”内容;3、去掉前面的分号修改成为“date.timezone = PRC”即可。
    阅读数:838 php5.4
  • php pdo 错误处理怎么设置

    php pdo错误处理设置方法:1、设置“PDO::ERRMODE_SILENT”,然后以“$pdo->errorInfo()”的形式获取错误信息;2、设置“PDO::ERRMODE_WARNING”,查看“E_WARNING”错误;3、设置“PDO::ERRMODE_EXCEPTION”,然后以“try{}cath(){}”输出错误信息。
    阅读数:903 pdo php
  • php怎么实现3秒跳转页面

    php实现3秒跳转页面的方法:1、使用“header('Refresh:3,Url=页面地址')”语句;2、使用“echo "<meta http-equiv='refresh' content='3; url=页面地址'>";”语句。
    阅读数:316 php 跳转页面