简体   繁体   English

无法修改标题信息-标题已发送

[英]Cannot modify Header Information - headers already sent

I have encountering a problem.. 我遇到一个问题..

It outputted an error : Cannot modify header information.. 输出错误:无法修改标题信息。

What would be the cause? 是什么原因? And how could i fix it.. Thanks for the help.. I've check all, but then still I cannot fix it. 以及我该如何解决。.感谢您的帮助..我已经检查了所有内容,但仍然无法修复。 What would be the problem? 有什么问题吗?

Here is my code below: 这是我的代码如下:

<!DOCTYPE html>
<html dir="ltr" lang="en-US"><head><!-- Created by Artisteer v4.3.0.60747 -->
    <meta charset="utf-8">
    <title>Home</title>
    <meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width">

    <link rel="stylesheet" href="style.css" media="screen">
    <link rel="stylesheet" href="style.responsive.css" media="all">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Salsa|PT+Sans&amp;subset=latin">

    <script src="jquery.js"></script>
    <script src="script.js"></script>
    <script src="script.responsive.js"></script>


<script>jQuery(function ($) {
    'use strict';
    if ($.fn.themeSlider) {
        $(".art-slidecontainera65d557e889141cb8638b82feda1c335").each(function () {
            var slideContainer = $(this), tmp;
            var inner = $(".art-slider-inner", slideContainer);
            inner.children().filter("script").remove();
            var helper = null;

            if ($.support.themeTransition) {
                helper = new BackgroundHelper();
                helper.init("fade", "next", $(".art-slide-item", inner).first().css($.support.themeTransition.prefix + "transition-duration"));
                inner.children().each(function () {
                    helper.processSlide($(this));
                });


            } else if (browser.ie && browser.version <= 8) {
                var slidesInfo = {
".art-slidea65d557e889141cb8638b82feda1c3350": {
    "bgimage" : "url('images/slidea65d557e889141cb8638b82feda1c3350.jpg')",
    "bgposition": "0 0",
    "images": "",
    "positions": ""
},
".art-slidea65d557e889141cb8638b82feda1c3351": {
    "bgimage" : "url('images/slidea65d557e889141cb8638b82feda1c3351.jpg')",
    "bgposition": "0 0",
    "images": "",
    "positions": ""
}
                };
                $.each(slidesInfo, function(selector, info) {
                    processElementMultiplyBg(slideContainer.find(selector), info);
                });
            }

            inner.children().eq(0).addClass("active");
            slideContainer.themeSlider({
                pause: 2600,
                speed: 600,
                repeat: true,
                animation: "fade",
                direction: "next",
                navigator: slideContainer.siblings(".art-slidenavigatora65d557e889141cb8638b82feda1c335"),
                helper: helper
            });


        });
    }
});
</script></head>
<body>
<div id="art-main">
<header class="art-header">

    <div class="art-shapes">

            </div>

<h1 class="art-headline">
    <a href="index.php">FPES</a>
</h1>
<h2 class="art-slogan">Faculty Performance Evaluation System.</h2>

<?php  
//connect to the database 
$connect = mysql_connect("localhost","root",""); 
mysql_select_db("db_fpes",$connect); //select the table

if(isset($_POST['btn_submit'])){
    $username = $_POST['username'];
    $password = $_POST['pass'];
    $result  = mysql_query ("SELECT * FROM professors where fac_stat = 1 and Faculty_code = '".$username."' and Faculty_code = '".$password."' ");
    if($username == 'admin' && $password == 'admin' && mysql_num_rows($result) == 0 ){
                header('Location: admin/home.php'); die;
    }
    else
    {
            $row = mysql_fetch_assoc($result);
            if($row['system_user'] == 1){
                header('Location: Grading/index.php'); die;
            }
            else if($row['system_user'] == 2){
                header('Location: Secretary/home.php'); die;
            }
            else
                header('Location: index.php');  die;
    }
}
?>
<nav class="art-nav">
    <ul class="art-hmenu"><li><a href="home.html" class="active">Home</a></li>
    <li><a href="add-profile.html">About Us</a></li>

</ul> 
</nav>
</header>
<div class="art-sheet clearfix">
            <div class="art-layout-wrapper">
                <div class="art-content-layout">
                    <div class="art-content-layout-row">
                        <div class="art-layout-cell art-content"><article class="art-post art-article">                           
                <div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout-wrapper layout-item-0">
<div class="art-content-layout layout-item-1">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-2" style="width: 100%" >
        <p></p><div id="a65d557e889141cb8638b82feda1c335" style="position: relative; display: inline-block; z-index: 0; margin: 0px;  border-width: 0px;  " class="art-collage">
<div class="art-slider art-slidecontainera65d557e889141cb8638b82feda1c335" data-width="900" data-height="287">
    <div class="art-slider-inner">
<div class="art-slide-item art-slidea65d557e889141cb8638b82feda1c3350" >


</div>
<div class="art-slide-item art-slidea65d557e889141cb8638b82feda1c3351" >


</div>

    </div>
</div>
<div class="art-slidenavigator art-slidenavigatora65d557e889141cb8638b82feda1c335" data-left="1" data-top="1">
<a href="#" class="art-slidenavigatoritem"></a><a href="#" class="art-slidenavigatoritem"></a>
</div>



    </div>


        <p>
        </p><p>
        </p>
    </div>
    </div>
</div>
</div>
<div class="art-content-layout layout-item-1">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-3" style="width: 67%" >
        <h2><span style="color: rgb(128, 0, 0); line-height: 51px; font-size: 40px;">Welcome&nbsp</span><span style="color: rgb(108, 127, 147); line-height: 31px; font-size: 28px;">to our site!</span></h2>
        <h3><img width="250" height="195" alt="" src="images/1037312_small500.jpg" style="float: left; margin-right: 15px;" class="">Performance Faculty Evalutaion System.&nbsp;</h3>
        <p>Insert Description Here!.<br></p>
    </div>

    <div class="art-layout-cell layout-item-4" style="width: 33%" >
    <form method = "post" action = "">
        <h1>Please Login<br></h1><p style="margin-top: 10px;"> Username: <input type="text" name = "username" >&nbsp;</p><p>
        <p> Password: <input type="text" name = "pass"></p><p style="text-align: right;">&nbsp;
        <input type = "submit" name = "btn_submit" class="art-button" value = "Login"/><br></p>
    </form>
    </div>
    </div>
</div>



</article></div>
                    </div>
                </div>
            </div>
    </div>
<footer class="art-footer">
  <div class="art-footer-inner">
<p>GoMiracles © 2014 - 2015. All Rights Reserved.<br></p>
  </div>
</footer>

</div>


</body></html>

Headers already sent is an issue where you try to redirect an user with header() or when you try to start a session session_start() when the browser already rendered content (for example html, but can also be a PHP echo statement for example). Headers already sent header()是一个问题,您尝试使用header()重定向用户,或者当浏览器已经呈现内容(例如html,但也可以是PHP echo语句session_start()时尝试启动会话session_start()时。

To fix the issue, check if you have any echo() statements or raw HTML before sending headers, and check if you do not have whitespaces in front of <?php . 要解决此问题,请在发送标头之前检查是否有任何echo()语句或原始HTML,并检查<?php前面是否没有空格。

A more detailed answer to help you fix this issue can be found here: https://stackoverflow.com/a/8028987/4274852 可在此处找到更详细的答案,以帮助您解决此问题: https : //stackoverflow.com/a/8028987/4274852

I suspect you did not provide us with all your code, as I cannot find any specific problems in yours at the moment. 我怀疑您没有向我们提供所有代码,因为我目前无法在您的代码中找到任何具体问题。 I hope the link above helps you to debug your code, if not: Make sure to post everything above your PHP code. 我希望上面的链接能帮助您调试代码,如果不能:请确保将所有内容发布到PHP代码之上。

Just a note: I see you are still using mysql_query statements, which are deprecated. 请注意:我看到您仍在使用不推荐使用的mysql_query语句。 Use msqli or PDO instead. 请改用msqliPDO

Edit 编辑

I see you posted your code, try replacing all your PHP code at the top of your page instead of in the middle and it should work. 我看到您发布了您的代码,请尝试在页面顶部而不是在页面顶部替换所有PHP代码,它应该可以工作。 In your current code, you have raw HTML before the PHP code ( <h1> and <p> elements in this case), which makes it impossible to send more header data using header() , as all headers were already sent before rendering the page. 在当前代码中,PHP代码之前有原始HTML(在本例中为<h1><p>元素),这使得无法使用header()发送更多的标头数据,因为所有标头均已在呈现该标头之前发送过页。

I editted your code to fix the issue hopefully, you can find it here (instead of posting it here, which would make an awkward long answer): 我编辑了您的代码以希望解决此问题,您可以在这里找到它(而不是在此处发布它,这将导致一个尴尬的漫长答案):

http://pastebin.com/0JfBdjU5 http://pastebin.com/0JfBdjU5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM