php在iis5下使用setcookie + header('Location')导致cookie失效的bug
那多记忆 2009-9-4 21:49:10
今天遇到一个奇怪的问题 emlog在一个 iis5 php4.4.6 的环境下,登录的时候我们是先写cookie 然后 header location到首页,但是在这个环境下只要有 header location 服务器就不发送cookie了。。去掉header location 就ok
我上网查找了一下,这是iis5的一个bug,其他服务器和II7没有这个问题
下面是我查到相关资料
微软官方对于这个bug的说明
http://suppo
另外在php在线手册的评论中也有一位网友发现了这个问题
http://cn.ph
评论内容(原文 + 翻译):
setcookie + header Location + IIS 5 = Trouble
It took me a long time to figure out what was causing a missing cookie in one system while it worked perfectly in another...
这个让我用了很长的时间去查出cookie在一个系统上丢失却在其他系统上正常原因
See this one: http://support.microsoft.com/kb/q176113/
In short, this WILL NEVER WORK IN IIS 5:
简单的说,下面的代码不能在iis5上成功运行
<?php
header("Pragma: no-cache");
header('Location: http://www.example.com/');
setcookie('AA','1',0,'/');
setcookie('BB','2',time() + 24 * 3600,'/');
?>
You will ONLY get the Location Header, everything else will be "cut out" by IIS 5 CGI implementation.
你只能得到Location Header,其他的东西全部都在iis5的CGI执行中被剪掉了
Solutions:
解决方案
1- Migrate to Apache/IIS6/Whatever
迁移到Apche IIS6 或者其他的平台上
2- Use a Non Parsed Header Script (nph-*.php)
使用不处理头部的脚本文件
3- Try with header('Refresh: 0; $URL');
尝试发送这样的头来实现页面跳转header('Refresh: 0; $URL');
I hope this helps somebody not to spend hours knocking his/her head.
我希望这些能帮助某些人不用浪费很多时间来敲头(笑)
用php写了一个银行口令卡生成程序,可以生成类似银行口令卡的图片或者表格。







