Jump to content

Cannot Modify Headers


Ptsface12

Recommended Posts

Hey,

For some reason I got the following error:

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\index.php:5) in C:\xampp\htdocs\index.php on line 37

 

Line 37:    header('location: me.php');

 

My code is:

<?php
session_start();
include 'includes/core.php';
?>
<head>
<title><?php echo $_SESSION['shortname']; ?> » Home </title>
<link rel="stylesheet" href="css/login.css" />
</head>
<body><div id="container">

<div id="head">

<a href='index.php'>

	<div id='logo'>

	</div>

	</a></div>
<div id="login_background">


<div id="login">New to <?php echo $_SESSION['shortname']; ?>? <strong><u><a href="register.php">REGISTER HERE! </a></u></strong><br />
<?php
if (isset($_POST['log_button'])) {
  $user = $_POST['username'];
  $pass = $_POST['password'];
  include ('includes/config.php');
  $con = mysql_connect($host, $dbuser, $dbpass) or die("Unable to connect!");
mysql_select_db($db, $con);
$sql="SELECT * FROM users WHERE username='$user' and password=MD5('$pass')";
$result=mysql_query($sql);

$count=mysql_num_rows($result);
if($count==1){
   $_SESSION['username'] = $user;
   header('location: me.php');
}
else {
echo "Wrong Username or Password";
}
  }
  ?>
      <br />

            <form method="post">
              <p>Username 
            :<br />

            <input type="text" name="username" id="username" value="Username" onFocus="if (this.value == 'Username') this.value = '';" />
              </p>
              <p>
              Password:<br />
                
                <input type="password" name="password" id="username" value="Password" onFocus="if (this.value == 'Password') this.value = '';" />
                <br />
                
                      </p>
              <center><align='right'><input type="submit" name="log_button" value="Sign In" /></align></center>

      </form>
    </div>

</div>

</div>

<br />

</body>

 

Any help is appreciated!

 

Best Wishes,

Ptsface12

Link to comment
https://forums.phpfreaks.com/topic/242666-cannot-modify-headers/
Share on other sites

<?php
if (isset($_POST['log_button'])) {
  $user = $_POST['username'];
  $pass = $_POST['password'];
  include ('includes/config.php');
  $con = mysql_connect($host, $dbuser, $dbpass) or die("Unable to connect!");
mysql_select_db($db, $con);
$sql="SELECT * FROM users WHERE username='$user' and password=MD5('$pass')";
$result=mysql_query($sql);

$count=mysql_num_rows($result);
if($count==1){
   $_SESSION['username'] = $user;
   header('location: me.php');
}
else {
$message = "Wrong Username or Password";
}

 

that need to be near the top before any html is displayed

 

then where you want message if applicable

 

if(isset($message)) echo $message;

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.