php で p3p ヘッダーを設定する方法: 1. HOST を編集して「127.0.0.1 www.a.com」を追加します; 2. a_setcookie.php や a_getcookie.php などのファイルを作成します; 3. p3p ヘッダーを設定しますスルーヘッダー 以上です。
この記事の動作環境: Windows 7 システム、PHP バージョン 7.1、Dell G3 コンピューター。
PHP で p3p ヘッダーを設定するにはどうすればよいですか?
PHP は P3P ヘッダーを設定することで COOKIE へのクロスドメイン アクセスを実装します
私のシステムは CentOS (Linux カーネル)です
ホストの編集
vi /etc/hosts
参加
127.0.0.1 www.a.com 127.0.0.1 www.b.com
最初に: 次の内容を含む_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"); ?>
次に: 次の内容を含む_getcookie.php ファイルを作成します:
<?php var_dump($_COOKIE); ?>
最後に、次の内容の b_setcookie.php ファイルを作成します:
<script src="http://www.a.com/a_setcookie.php?id=www.b.com"></script>
--------------------------- -
3 つのファイルが作成された後、ブラウザを通じて 1 つずつアクセスします。
http://www.b.com/b_setcookie.php http://www.a.com/a_getcookie.php
b.com ドメインにアクセスするときに、Cookie の値が設定されていないことがわかります。 a.com ドメイン内。
次に、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 値が設定されていることがわかります。
最後に、COOKIE へのクロスドメイン アクセスに対する制限が厳しいのは IE だけのようです。上記のコードは FIREFOX でテストされており、P3P ヘッダー情報を送信しなくても成功する可能性があります。
==========================================
推奨学習: 「PHP ビデオ チュートリアル 」
上記の P3P コードの意味は、Fiddler を介して簡単に知ることができます
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ヘッダーを設定する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。