2

输入用户名和密码后,显示此错误

警告:无法修改标头信息 - 标头已由 /*** 中的(输出开始于 /storage/****************/public_html/Include/Header.php:1)发送*************/public_html/user_login.php 第 17 行

在本地服务器它工作正常,但上传到 000webhost 后它给出了上述错误

请帮助我,谢谢

<?php 
session_start();
include("/storage/****************/public_html/Include/Header.php"); 
include('/storage/****************/public_html/Include/Navbar.php');
include('/storage/****************/public_html/Include/db.php');


    ?>
       <?php
   if(isset($_POST['submit'])){
       $u_username=$_POST['u_username'];
       $u_password=$_POST['u_password'];
       $sql=mysqli_query($link, "SELECT * FROM tbl_user where u_username='$u_username' and u_password='$u_password'");
       $result=mysqli_fetch_array($sql);
       if($result['u_username']== $u_username and $result['u_password']== $u_password){
           $_SESSION['user']=$u_username;
             header("location:/storage/****************/public_html/123.php");


       }else{

           $error= "<div class='alert alert-danger'>ID or Password Incorrect</div>";

       }

   }

  ?>

   <div class="row">
    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

            <ul class="nav navbar-nav navbar-left" id="nav">
                <li><a href="index.php"><i class="fa fa-home"></i> Home</a></li>

            </ul></div>


    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
   <!--Main Body-->
     <div class="container">
         <div class="panel panel-primary col-md-9">
            <div class="panel-heading">
                <h3>Admin Login</h3>
            </div>
            <div class="panel-body col-md-7">
              <form class="form-horizontal" action="" method="post">
             <div class="form-group">
                 <label for="Name" class="col-md-5">Your username: *</label>
                 <div class="col-md-7">
                     <input type="text" required name="u_username" class="form-control" placeholder="Your ID Here...">
                 </div>
             </div>
            <div class="form-group">
                 <label for="Name" class="col-md-5">Your Password: *</label>
                 <div class="col-md-7">
                     <input type="Password" name="u_password" class="form-control" placeholder="Your Password Here..." required>
                 </div>
             </div>
             <div class="form-group">
                 <label for="Name" class="col-md-5"></label>
                 <div class="col-md-7 ">
                     <?php if(isset($error)){
                            echo $error; }?>
                 </div>
             </div>
             <div class="form-group">
                 <label for="Name" class="col-md-5"></label>
                 <div class="col-md-7">
                     <input type="submit" name="submit" value="Login" class="btn btn-success btn-block">
                 </div>
             </div>

            <div>
                <h3>Note:</h3> 
                <p>If NOT Registered! Please <a href="contact.php">Contact Us</a>.</p>
            </div>


                </form>


         </div>

     </div>
</div><br>

   <!--End of Main Body-->
   <?php 
include("/storage/****************/public_html/Include/Footer.php")
?>
4

4 回答 4

2

在包含之后,删除以下两行:

?>
   <?php

因为,在关闭标签和打开标签之间,有多个空格发送到输出,这导致了这个警告。

最后,添加exit()afterheader()以停止脚本。

于 2018-03-01T10:24:54.360 回答
1

您必须在任何输出之前使用会话(即使是“空白输出或 html”)

于 2018-03-01T10:43:41.243 回答
1

Use ob_start() in Header.php file.

This function turn on output buffering so not output is sent from the script instead. the output is stored in an internal buffer.

Look here For More detail

于 2018-03-01T10:56:57.987 回答
0

您在输出一些代码后尝试修改 HTTP 标头。

您可能想要移动这些包括

include("/storage/****************/public_html/Include/Header.php"); 
include('/storage/****************/public_html/Include/Navbar.php');

在您对用户进行身份验证后。

它应该看起来像:

<?php 
session_start();
include('/storage/****************/public_html/Include/db.php');

if(isset($_POST['submit'])){
       $u_username=$_POST['u_username'];
       $u_password=$_POST['u_password'];
       $sql=mysqli_query($link, "SELECT * FROM tbl_user where u_username='$u_username' and u_password='$u_password'");
       $result=mysqli_fetch_array($sql);
       if($result['u_username']== $u_username and $result['u_password']== $u_password){
           $_SESSION['user']=$u_username;
         header("location:/storage/****************/public_html/123.php");

       }else{

           $error= "<div class='alert alert-danger'>ID or Password Incorrect</div>";

       }

   }
include("/storage/****************/public_html/Include/Header.php"); 
include('/storage/****************/public_html/Include/Navbar.php');

  ?>
于 2018-03-01T10:33:03.370 回答