Jump to content

Warning: Cannot modify header information - headers already sent by


bambinou1980

Recommended Posts

Hello,

 

I keephaving this annoying error and cannot work out why it is happening, any help would be more than appreciated please.

I looked online for help but cannot work out why data cannot be sent before the header or why there is data anyway sent before the header code....I am confused. I checked for blank spaces and things like that but nothing...

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\plus\admin\includes\header.php:21) in C:\xampp\htdocs\plus\admin\sign-in.php on line 29

 

<?phpsession_start();include('includes/header.php');include('includes/public-navbar.php');include('../db/dbconnect.php');?>         <?php        $username = "";                if(isset($_POST['submit'])) {        //process the form                if(isset($_POST["username"]) && $_POST["password"])        {          $query = "SELECT * FROM users WHERE username = 'admin' LIMIT 1";    $results = mysqli_query($connection, $query);                $password = $_POST["password"];        $admin = $_POST["username"];                while ($row = mysqli_fetch_row($results))        {        //If Admin name = md5 mysql recorded version        if(md5($password) != $row[2])        {          echo "wrong username/password!";                  }else{          header("Location: logged-in.php");          die();                    }           }     }  }         ?>          <!--Content-->                 <div class="row"><div class="col-md-4"></div><div class="col-md-4">                                 <form role="form" method="post" action="sign-in.php"><div class="form-group"> <label for="InputUsername">Username</label><input type="text" class="form-control" name="username" placeholder="Your Email" value="<?php echo htmlentities($username); ?>" required /></div>                        <div class="form-group"> <label for="InputPassword">Password</label><input type="password" class="form-control" name="password" placeholder="Your Password" required /></div>                                                <div class="form-group">                        <button type="submit" class="btn btn-default" name="submit">Submit</button>                        </div></form></div><div class="col-md-4"></div></div>                           <!--Content--> <?php include('includes/footer.php'); ?>

 
 
and here is my header.php

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
 
    <title>Admin Login</title>
 
    <meta name="description" content="">
    <meta name="author" content="">
 
    <link href="../css/bootstrap.min.css" rel="stylesheet">
    <link href="../css/style.css" rel="stylesheet">
 
  </head>
  <body>
 
    <div class="container-fluid">
<div class="row">
    <div class="col-md-12">
output started at C:\xampp\htdocs\plus\admin\includes\header.php:21

 

 

everything that is in your header.php file is output that's being sent to the browser. line 21 is just the end of all the output.

 

the best way of correcting this is to layout your page with any php code that determines what your page will do (the control logic), first. then put any php code that gets/produces the content on the page and the actual html/css/javascrpt markup at the end.

 

your form processing code is part of the control logic that determines what your page will do and it should come before the <!DOCTYPE html> tag.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.