Possible Duplicate:
Headers already sent by PHP
在這裏,我有奇怪的問題,以保護我的網頁,以檢查是會議開始,如果不是重定向到登錄,
<?php
require_once ('includes/config.inc.php');
// Start output buffering:
ob_start();
// Initialize a session:
session_start();
// Check for a $page_title value:
if (!isset($page_title)) {
$page_title = 'User Registration';
}
// If no first_name session variable exists, redirect the user:
if (!isset($_SESSION['first_name'])) {
$url = BASE_URL . 'index.php';
ob_end_clean(); // Delete the buffer.
header("Location: $url");
exit(); // Quit the script.
}
?>
我得到這個錯誤:在第8行:
session_start() [function.session-start]: Cannot send session cache limiter - headers already sent
有人可以發佈一個很好的解決方案來檢查會話是否開始,如果沒有重定向到登錄頁面,否則留在頁面上? Txanks
在打開'<?php'之前刪除空格。它被視爲發送到瀏覽器的文字輸出,之後PHP不能設置任何額外的標題(如會話cookie) – 2012-04-07 00:46:58
如果在顯示的代碼中的<?php'之前沒有空格(根據您的代碼)必須在你的'config.inc.php'中要麼是空格,要麼在該文件中做一些其他的輸出。 – 2012-04-08 06:55:02
或auto_prepend_file – Leigh 2012-06-15 13:08:06