如何在PHP中使用下面的設置重定向而不會出現頭部輸出錯誤,我明白,在設置頭部之前沒有任何東西可以打印到瀏覽器,我正在尋找解決方案,而不是解釋爲什麼會發生請。如何在PHP中重定向而不發生標題錯誤?
<?PHP
// include header
include ('header.inc.php');
// In my body section file if this is a page that requires a user be logged in then
// I run a function validlogin($url-of-page-we-are-on); inside of that file
//the function is below, it outputs a redirect to login page if not logged in
// include body of page we want
include ('SOME-FILE-HERE.php');
// include footer
include ('footer.inc.php');
// here is the function that is in the body pages, it is only called on a page that we require a logged in user so there are hundreds of pages that do have this and a bunch that don't, it's on a page to page basis
function validlogin($url) {
if ($_SESSION['auto_id'] == '') {
$msg = 'Please login';
$_SESSION['sess_login_msg'] = $msg;
$_SESSION['backurl'] = $url;
$temp = '';
header("Location: /");
exit();
}
}
?>
我想用戶PHP的頭功能,而不是一元或JavaScript重定向
而且,這裏maintainning的需要登錄與否頁面的列表不是一個選項,如果可能的
這就是我所做的,閱讀我的問題的更新部分 – JasonDavis 2009-08-10 23:31:40
對不起,II有關於同一問題的另一個問題,我沒有意識到我是在這個問題上,反正這就是我最終完成它的方法,它工作得很好 – JasonDavis 2009-08-10 23:33:02