apache或者php,怎么设置页面的cookies?
curl一个网站,法国天气网。
返回的信息是
Merci d'accepter les cookies
Pour accepter les cookies :
Sur Internet Explorer : Outils > Options Internet > Confidentialité > Avancé
Sur Firefox: Outils > Options > Vie privée > Cookie > Accepter les cookies
Nous vous informons que vous pouvez vous opposer à l'enregistrement de ces cookies en configurant votre ordinateur selon les modalités détaillées sur le site de la CNIL. (http://www.cnil.fr)
大致意思是:
谢谢您接受cookies
要接受Cookie:
IE浏览器:工具> Internet选项>隐私>高级
在Firefox:工具>选项>隐私>饼干>接受Cookies
我们告诉你,你可能会反对cookie的配置您的计算机的CNIL的网站上详细登记。(http://www.cnil.fr)
HTTP/1.1 302 Found Date: Thu, 24 Jan 2013 16:09:14 GMT Server: Apache Set-Cookie: jknch=hcnkj; path=/; domain=meteofrance.com Location: http://token.meteofrance.com/?u=%68%74%74%70%3A%2F%2F%66%72%61%6E%63%65%2E%6D%65%74%65%6F%66%72%61%6E%63%65%2E%63%6F%6D%2F%66%72%61%6E%63%65%2F%61%63%74%75%2F%61%63%74%75%3F%70%6F%72%74%6C%65%74%5F%69%64%3D%39%30%31%33%36%26%64%6F%63%75%6D%65%6E%74%5F%69%64%3D%32%37%33%35%34&s=%73%69%6D%2D%70%6F%72%74%61%69%6C&x=%DC%45%F1%A6%56%AD%A9%DE Content-Length: 0 Content-Type: text/html HTTP/1.1 302 Found Date: Thu, 24 Jan 2013 16:09:19 GMT Server: Apache Location: http://france.meteofrance.com/NoCookie.htm Content-Length: 0 Connection: close Content-Type: text/html HTTP/1.1 200 OK Date: Thu, 24 Jan 2013 16:09:20 GMT Server: Apache ETag: "8613ee-89f-4d0d0d2028c80" Accept-Ranges: bytes Xcache: Version 1.2 for Apache 2.2 Last-Modified: Thu, 24 Jan 2013 15:39:23 GMT Content-Length: 2207 Content-Type: text/html
Date: Thu, 24 Jan 2013 16:09:20 GMT
Server: Apache
ETag: "8613ee-89f-4d0d0d2028c80" Accept-Ranges: bytes Xcache: Version 1.2 for Apache 2.2 Last-Modified: Thu, 24 Jan 2013 15:39:23 GMT
Content-Length: 2207
Content-Type: text/html
::::
第一个 HTTP/1.1 302
设置了 cookie(Set-Cookie: jknch=hcnkj;...)
跳转到 http://token.meteofrance.com....
第二个 HTTP/1.1 302
跳转到 http://france.meteofrance.com/NoCookie.htm
这是因为你没有传递第一段设置的 cookie ,所以会出现要求启用 cookie 的提示
这是用 php 代码实现的
1、
setcookie('jknch', 'hcnkj', 0, '/', 'meteofrance.com');
header("Location: http://token.meteofrance.com?...");
2、
if(isset($_COOKIE) && $_COOKIE['jknch'] == 'hcnkj') {
//正常的页面处理
}else {
header("Location: http://france.meteofrance.com/NoCookie.htm");
}