Jump to content

Warning: Cannot modify header information - headers already sent by.....


mikebyrne

Recommended Posts

Im setting up a login page with redirection but im getting the following error

 

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

 

Line 305 is: header("Location: ../MainPage/first.php");

 

My php for my login.php looks like this

 

    <?php
include("adminconnect.php");

$tbl_name="adminusers";

if(isset($_POST['uname']) && isset($_POST['pword']))
{
// Define $myusername and $mypassword
$uname=mysql_escape_string($_POST['uname']);
$pword=mysql_escape_string($_POST['pword']);


$sql="SELECT * FROM $tbl_name WHERE username='$uname' and password='$pword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

        /* grab the usertype */
        $r = mysql_fetch_array($result);
        
        /* We will verify that the num_rows exists, for some reason you weren'y verifying this  */
        /* After verifying, we will then set the session, this is assuming that there is a column  */
        /* in your table named 'type' and its value is either '1' or '2'                                     */
        if ($count > 0) {
               $_SESSION['usertype'] = $r['usertype'];
               $logged = true;
        } else {
               echo "Wrong Username/Pad =ssword.";
        }
            
if ($_SESSION['usertype'] == "2" && $logged == "true") 
       {
              header("Location: ../Admin_files/start.php");
       }

else if ($_SESSION['usertype'] == "1" && $logged == "true") 
       {
           
	     header("Location: ../MainPage/first.php");
       }
}
?>
      <form action="../MainPage/login.php" method="POST">
      <div align="right">Pleas enter your Login Name</b>

<BR>(This is the name you signed up with)</div>
    </td>
    <td width="50%"> 
      <input type="text" name="uname" size="12" maxlength="50" class="field">
    </td>
  </tr>
  <tr> 
    <td class="bgrl"> 
      <div align="right">Please enter your <b>password</b></div>

    </td>
    <td width="50%" class="bgrl">
      <input type="password" name="pword" size="18" class="field">
    </td>
  </tr>
  <tr><td> </td>
    <td>
    <input type="submit" value="Login »" class="submit"></form></td>
  </tr>



  <tr><td colspan="2" class="genericside"><span class="t11bw">Forgotten your password?</span></td>
  </tr>
  <tr valign="top"> 
    <td class="alignright">
    <form name="passwordreminder" action="/member_login.php" method="post">
    <input type="hidden" name="type" value="passwordreminder">
    Please enter your email here:</td>

<td><input type="text" name="reminderemail" class="field" maxlength="50"><br>
<input type="submit" value="Send Password »" class="submit">
    </form> 

 

Link to comment
Share on other sites

You have output on line 5 in login.php which is causing the error. This may be your problem here:

    <?php

Notice the space before the php tag, that will be seen as output and is most probably causing the error. You cannot have any form of ouput before the use of header

Link to comment
Share on other sites

I am not an expert, but I have just learned that a header redirect should always be put above the HTML-code. So completely at the top. The browser should not have had any code to work with yet, otherwise it won't work either.

Try to put the whole lot at the top... (because otherwise the browser has already used a header.

Link to comment
Share on other sites

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.