php下通常我们用header来提示浏览器下载一个文件: 

=================================

<?php//session_start();header("content-type:text/html; charset=utf-8"); header( "Content-type:application/text/plain");if(strpos(SERVER['HTTP_USER_AGENT'],"MSIE")) header( 'Content-Disposition: attachment; filename="'.urlencode("名字").'.txt"' );//如果是ie存为的名字要urlencode else header( 'Content-Disposition: attachment; filename="名字.txt"' );//存为的名字header( 'Content-Transfer-Encoding: binary' ); echo “z这里是文本内容”;?>

==========================

这样浏览器就会自动下载一个txt文件而不是直接显示文本。

那么我们想在下载之前,验证一下用户登录了没有。势必要用到session_start();如果把上面那个注释去掉,就会出现如下图:

这令我百思不得其解。

用百度搜了下中文,结果全是说改浏览器注册表的,离谱。

谷歌了下英文 session_start ie6 can't download 第一个结果就有了看来还是要多搜英文啊。

http://bytes.com/topic/php/answers/554529-internet-explorer-6-refusing-let-me-download

http://stackoverflow.com/questions/117372/cant-download-file-in-ie7-but-there-isnt-any-problem-in-firefox-chrome-etc

解决方法:1(推荐)

增加一条header('Cache-Control: max-age=0');

解决方法2:

增加一条

session_cache_limiter("private");

原因:

session_start()会默认发出一条包含"no-store" 信息的header。这条header表示希望浏览器不要缓存这个页面的有关数据到硬盘。(登录的页面数据嘛。。缓存到硬盘就有问题了。)

ie君接到这条消息后很傻很天真的什么都不缓存,将所有文件全部放在内存中。当服务器希望浏览器将一个文件下载到硬盘,ie君就被这个bug搞昏了。而且无法采取有效的错误处理方式来应对这个问题。当你尝试下载这个输出页面时,他就会爆这个未知类型的错误。其他浏览器均不会犯这种迷糊。