2012-07-05 40 views
0

每当我打开网页我收到以下错误:PHP头(位置)错误

[04月2012年17点10分45秒] PHP的警告:不能更改头信息 - 头已经发出(输出开始于/home/test/public_html/admin/header.php:39) /home/test/public_html/admin/edAgent.php on line 80

[04-Jul-2012 17:10: 55] PHP警告:无法修改标头信息 - 已在 /home/test/public_html/admin/edAg中输出的标头(在/home/test/public_html/admin/header.php:39开始输出) ent.php线80条上

件的代码,包括标头:

Encoding头:

header('Content-Type: text/html; charset=utf-8'); 

登录重定向头:

if(!isset($_SESSION["login"])OR $_SESSION["login"]!=1){   
    header('Location: login.php'); 
    exit;  
    } 

检查是否记录使用r的权限编辑:

if($level!='4') { 
    header('Location: acd.php?msg=1'); 
    exit; 
} 

检查,如果ID存在:

if ($nUsers==0) {  
    header('Location: acd.php?msg=2'); 
    exit;  
} 

检查,如果信息是可编辑:

if($access != '4') {   
    header('Location: acd.php?msg=1'); 
    exit;   
} 
+0

看看/home/test/public_html/admin/header.php的39线 - 错误信息给你一个真正的大线索有 – 2012-07-05 09:58:56

+0

为什么你使用退出? – Gntem 2012-07-05 09:59:05

+0

39号线上有什么代码? – 2012-07-05 09:59:20

回答

1

如果头已经发送JS方法应该工作。

print '<script type="text/javascript">window.top.location.href = "'. $myurl .'";</script>'; 
2

如果你输出任何东西到屏幕,然后,标题将写入。因此,如果您打算在代码中使用header(),则必须在输出任何内容之前执行此操作,或者在开始时使用ob_start()开启输出缓冲。

0

add ob_start();在页面的开始和ob_end_flush();和页面的结尾处。虽然在header()之后不应该有任何输出代码,但可以在函数中尝试存储header()。

希望它有帮助