php - 无法修改 header 信息 - header 已发送(混淆)

标签 php css header

<分区>

我正在制作一个将与 phpVMS 的登录系统集成的脚本。

我已经让它工作了,如果有人进入登录页面,它就会显示出来。我怎样才能做到当有人打开网页但没有登录时,它会将他们发送到登录页面?

目前,我得到错误:

Cannot modify header information - headers already sent by (output started at /home/a4366948/public_html/mindfulhacker/private/man/index.html:11) in /home/a4366948/public_html/mindfulhacker/private/man/index.html on line 16

我看到了另一篇关于同样问题的帖子,但我对如何让样式表同时工作感到困惑——只有一个未格式化的页面没有意义!

    <html xmlns="http://www.w3.org/1999/xhtml"><head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <meta http-equiv="Content-Language" content="en-gb">
<meta name="language" content="eng">
<meta name="resource-type" content="document">
        <link rel="stylesheet" href="style.css" type="text/css">        
                    <title>Management System || CCVG</title>
<?php include('/home/a4366948/public_html/core/codon.config.php'); ?>
                                        </head>
                    <body>
                        <div class="container">
                            <div class="pagetitle">CapitalConnect Virtual Group - Management System</div>
                            <?php
                                if(Auth::LoggedIn()) {
                            ?>
                            <div class="menu"><table class="tb_blue_full margin_10" align="center" border="0" cellpadding="0" cellspacing="0" width="780"><tbody><tr><td class="cell_blue_botright" height="25" width="260"><div align="center"><strong><a href="/home/login_sso.php">Away Status</a></strong></div></td><td class="cell_blue_botright"  height="25" width="260"><div align="center"><strong><a href="/home/status.php">Students</a></strong></div></td><td class="cell_blue_bot" height="25" width="260"><div align="center"><strong><a href="/bookings/calendar.php">Classes</a></strong></div></td></tr></tbody></table></div>
                           <?php
} else {

header("Location: ".url('/login'));
exit;

}
?>
        <div style="clear: both;">&nbsp;</div>
</div>
</body></html>

最佳答案

header 调用之前您有一些内容。那是被禁止的。您必须将其移至顶部,例如:

<?php
    if(!Auth::LoggedIn()) {
        header("Location: " . url("/login"));
        die();
    }
?>
<html>
<!-- … -->

关于php - 无法修改 header 信息 - header 已发送(混淆),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27642552/

上一篇:html - CSS 显示 : block doesnt work

下一篇:html - z-index 似乎无法正常工作

相关文章:

php - CKEditor 会将根附加到我的图像链接中

php - 如何修复PHP中的“ header 已发送”错误

php - array_unique 函数后的数组作为 JSON 响应中的对象返回

php - 通过过程或面向对象风格调用函数的区别

jquery - Div 在点击时显示,但在使用 CSS 和 Jquery 第二次点击时不隐藏,不使用按钮,而是 <li> 标签中的类

javascript - 无法避免一个 div 踩到另一个 div

Android - ListActivity,添加页眉和页脚 View

html - 修复 css,使其相对于它的子项(/responsive)

javascript - 通过 PHP 将数据从 SQL 数据库移动到 JavaScript 中的数组

html - 更改窗口大小时文本超出 div 的边框