background image

<? 
header(“location:../test.php”); 
?> 
</body></html> 
只能这样: 
<? 
header(“location:../test.php”); 
?> 
<html><head></head><body>…</body></html> 
即 header 函数之前不能向客户发送任何数据. 
 
 
例 2: 
asp 中

 

<html><head></head><body> 
<% 
response.redirect “../a.asp” 
response.redirect “../b.asp” 
%> 
</body></html> 
结果是重定向 a.asp 文件. 
php 呢? 
<? 
header(“location:../a.php”); 
header(“location:../b.php”); 
?> 
<html><head></head><body></body></html> 
我们发现它重定向 b.php. 
原来在 asp 中执行 redirect 后不会再执行后面的代码. 
而 php 在执行 header 后,继续执行下面的代码. 
在这方面上 php 中的 header 重定向不如 asp 中的重定向.有时我们要重定向后,不能执行后
面的代码: 
一般地我们用 
if(…) 
header(“…”); 
else 

… 

但是我们可以简单的用下面的方法: 
if(…) 
{ header(“…”);exit();}
还要注意的是,如果是用 Unicode(UTF-8)编码时也会出现问题,需要调整缓存设置.