Jump to content

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;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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