Php 重定向到基本URL无效

Php 重定向到基本URL无效,php,Php,我需要让成员只能访问我的index.php页面。因此,我在index.php文件开头的php脚本检查用户名是否在会话中,如果不是,它应该自动将用户重定向到我的login.php页面。 所以我的登录页面应该是基本URL页面。我还定义了“BASE_URL”、“mywebsite.com/login.php”;在我的verify.php脚本中。 但是当我导航到我的索引页面时,我只得到一个空白屏幕错误,脚本'path/index.php'第11行出现了一个错误:无法修改标题信息-标题已经由path/in

我需要让成员只能访问我的index.php页面。因此,我在index.php文件开头的php脚本检查用户名是否在会话中,如果不是,它应该自动将用户重定向到我的login.php页面。 所以我的登录页面应该是基本URL页面。我还定义了“BASE_URL”、“mywebsite.com/login.php”;在我的verify.php脚本中。 但是当我导航到我的索引页面时,我只得到一个空白屏幕错误,脚本'path/index.php'第11行出现了一个错误:无法修改标题信息-标题已经由path/index.php:1开始的输出发送。 我的HTML之前没有任何空格,这可能是原因。我还尝试在我的login.php的头部使用BASE_href将BASE_URL设置为我的登录名,但没有成功。 这是我在索引文件开头的脚本:

<?php 
require_once ('verify.php'); 
$page_title = 'title';
ob_start();
session_start();
if (!isset($page_title)) {
$page_title = 'title';}
if (!isset($_SESSION['name'])) {    
$url = BASE_URL . ''; 
ob_end_clean();
header("Location: $url ");
exit();
}
?>
<!DOCTYPE html><html><head></head><body></body></html>
<?php
ob_end_flush();
?>
\n

; 如果现场{echo.$message; }否则{ mailEMAIL,'Site Error!',$message,'From:you@youremail.com'; 如果$e_编号!=e_通知{ echo“出现系统错误。我们为给您带来的不便深表歉意。”; } } } 设置错误处理程序“我的错误处理程序”; ?>
我找到了解决办法。答案是用UTF8编码,不带BOM。

显示可能与输出缓冲相关的验证内容。您可以测试头是否已通过发送,以查看头实际上已在代码中的哪个点发送@DavidGuyen我用我的验证内容进行了更新。在出现错误之前你没有获得任何信息吗?请检查源代码,看看是否有html标记。@FrankPresenciaFando在我的空白屏幕源代码中是..只有那个。
<?php 
define('LIVE', TRUE);
define('EMAIL', 'my_mail');
define ('BASE_URL', 'mywebsite.com/login.php');
define ('MYSQL', 'db.php');
function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) {
$message = "<p>An error occurred in script '$e_file' on line $e_line:      $e_message\n<br />"; 
$message .= "Date/Time: " . date('n-j-Y H:i:s') . "\n<br />";
$message .= "<pre>" . print_r ($e_vars, 1) . "</pre>\n</p>";
if (!LIVE) { echo '<div class="error">' . $message . '</div><br />';

} else {        
    mail(EMAIL, 'Site Error!', $message, 'From: you@youremail.com');
    if ($e_number != E_NOTICE) {
    echo '<div class="error">A system error occurred. We apologize for the inconvenience.</div><br />';
    }   }     } 
 set_error_handler ('my_error_handler');
 ?>