PHP标题("Location:$ url");

Mio*_*vic 0 php session http-headers

可能重复:
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.

}
?>
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误:第8行:

session_start()[function.session-start]:无法发送会话缓存限制器 - 已发送的标头

有人可以发布一个很好的解决方案来检查会话是否已启动,如果没有重定向到登录页面,那么留在页面上?Txanks

Oli*_*rth 5

这是你的问题:

    <?php 
^^^^
Run Code Online (Sandbox Code Playgroud)

在发送标头之前,您无法输出任何内容; 包括空格.