简体   繁体   中英

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).

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 .

A more detailed answer to help you fix this issue can be found here: 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.

Just a note: I see you are still using mysql_query statements, which are deprecated. Use msqli or PDO instead.

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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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