2

After entering username and password, showing this eror

Warning: Cannot modify header information - headers already sent by (output started at /storage/****************/public_html/Include/Header.php:1) in /****************/public_html/user_login.php on line 17

in localserver it works fine but after uploading to 000webhost it gives the above error

please help me, thanks

<?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")
?>
Xantium
  • 11,201
  • 10
  • 62
  • 89
Noman
  • 21
  • 2
  • move `session_start();` one line lower, place it under `include("/storage/****************/public_html/Include/Header.php"); ` and see if it helped – Michał Skrzypek Mar 01 '18 at 10:15
  • now it shows this Warning: session_start(): Cannot send session cache limiter - headers already sent – Noman Mar 01 '18 at 10:33

4 Answers4

2

After the includes, remove the two following lines :

?>
   <?php

Because, between close tag and open tag, there is multiple spaces sent to the output, which causes this warning.

Finally, add exit() after header() to stop the script.

Syscall
  • 19,327
  • 10
  • 37
  • 52
1

you have to use session before any outputs(even though 'blank output or html')

Alex
  • 1,148
  • 8
  • 30
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

Count
  • 1,395
  • 2
  • 19
  • 40
Mahesh K
  • 11
  • 3
0

You are trying to modify the HTTP Headers after you have output some code.

You might want to move these includes

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

to after you have authenticated the user.

It shoul look like:

<?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');

  ?>