Solved

Warning: Cannot add header information - headers already sent by (output started

Posted on 2003-12-02
5
5,786 Views
Last Modified: 2010-04-06
Hello,

I am getting error when ever I try to login to the admin area the error is


Warning: Cannot add header information - headers already sent by (output started at /home/virtual/site14/fst/var/www/html/auction/admin/index.php:2) in /home/virtual/site14/fst/var/www/html/auction/admin/index.php on line 23


Please help me solving that error. following is my php script which causing that error :-


<? session_start(); ?>
<?php include("../lib/inc.php"); ?>
<?php

      session_register("userid");
      $msg = "";
      if (isset($action)) {
      if ($ausername == "") {      
            $msg = "Please enter username";
      } else {
      if ($apassword == "") {      
            $msg = "Please enter password";
      }
      }

      if (($ausername <> "") && ($apassword <> "")) {      

          $query = "SELECT admin_id from auc_admin where usernm='$ausername' and passwd='$apassword'" ;
          $rsl = mysql_query($query);  
          $row = mysql_fetch_array($rsl)  ;
                  if ($row[0] <> "") {      
                        $userid = $ausername;
                        header ("Location:adminhome.php");
                        exit;                        
                  } else {
                        $msg = "Incorrect username and password";
                  }
            }
            }
?>
<HTML>
<head>
<title>:: ADMIN AUCTION :: Admin Login</title>
<!--link rel="stylesheet" href="../../css/styles.css" type="text/css"-->
<script language="JavaScript">
var haverr = 0;
function validateForm(fld) {
    haverr = 0;

    if (fld.ausername.value.length < 1) {
       alert("Please enter username");
         fld.ausername.focus();
         return (false);
    }
    else {
    if (fld.apassword.value.length < 1) {
       alert("Please enter password");
         fld.apassword.focus();
         return (false);
    }
    else {
       return (true);
    }
    }

    return (false);
}

</script>
</head>
<BODY BGCOLOR="#FFFFFF" TEXT="#08428C" LINK="#08428C" VLINK="#08428C" ALINK="#08428C" LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">
<BR><BR>
<TABLE BORDER=0 WIDTH=650 CELLPADDING=0 CELLSPACING=0 BGCOLOR="#FFFFFF" ALIGN="CENTER">
      <TR>
<TD>
      <CENTER>
                        <FONT FACE="Verdana, Arial, Helvetica, sans-serif" SIZE="4"><BR>
                        <BR>
                                                <FORM NAME=login method="post" onSubmit="return validateForm(this);" action="<?php echo $PHP_SELF ?>">
                              <TABLE WIDTH="400" BORDER="0" CELLSPACING="0" CELLPADDING="1" BGCOLOR="#336699">
                                    <TR>
                                          <TD>
                                                <TABLE WIDTH=100% CELLPADDING=3 ALIGN="CENTER" CELLSPACING="0" BORDER="0" BGCOLOR="#FFFFFF">
                                                      <TR BGCOLOR="#336699">
                                                            <TD COLSPAN="2" ALIGN=CENTER><FONT FACE="Tahoma, Verdana" SIZE="2" COLOR="#FFFFFF"><B>::
                                          Please log in for admin access ::</B></FONT></TD>
                                                      </TR>
                                                      <TR>
                                                            <TD></TD>
                                                            <TD> <FONT FACE="Verdana, Verdana, Arial, Helvetica, sans-serif" SIZE="2" COLOR=red><?php echo $msg; ?></FONT></TD>
                                                      </TR>
                                                      <TR>
                                                            <TD ALIGN=right> <FONT FACE="Verdana, Verdana, Arial, Helvetica, sans-serif" SIZE="2">
                                                                  Username                                                                  </FONT> </TD>
                                                            <TD>
                                                                  <INPUT NAME=ausername SIZE=20  VALUE="admin10">
                                                            </TD>
                                                      </TR>
                                                      <TR>
                                                            <TD ALIGN=right> <FONT FACE="Verdana, Verdana, Arial, Helvetica, sans-serif" SIZE="2">
                                                                  Password                                                                  </FONT> </TD>
                                                            <TD>
                                                                  <INPUT TYPE=password NAME=apassword SIZE=20  VALUE="adminpass">
                                                            </TD>
                                                      </TR>
                                                      <TR>
                                                            <TD></TD>
                                                            <TD>
                                                                  <INPUT TYPE=submit NAME=action VALUE="login">
                                                            </TD>
                                                      </TR>
                                                </TABLE>
                                          </TD>
                                    </TR>
                              </TABLE>
                        </FORM>
                                                </font>
                  </CENTER>
            </TD>
</TR>
</TABLE>
<p align="center"><font face="Tahoma" style="font-size: 8.5pt">©1997 - 2003 Wcws
Internet Inc. WS Auction.<br>
</font><br>
&nbsp;</p>
</BODY>
</HTML>

0
Comment
Question by:wcws
5 Comments
 
LVL 11

Accepted Solution

by:
Zontar earned 50 total points
ID: 9865481
If you've got anything before the opening PHP delimiter, that would definitely do it. And I do mean *anything* -- blank line, space, doesn't matter. The <? opening delimiter would also do it if PHP not configured to allow the short open tag. Change it to <?php and make sure there's absolutely nothing in that file before it. The fact that the error's shown as being in Line 2 suggests that might be the case. Also make sure there's no leading whitespace before the opening PHP delimiter in the include file as well.
0
 
LVL 11

Expert Comment

by:Zontar
ID: 9865498
      $query = "SELECT admin_id from auc_admin where usernm='$ausername' and passwd='$apassword'" ;

P.S. Tell me you're *not* storing passwords in the clear, please...
0
 
LVL 1

Expert Comment

by:cneelus
ID: 10078533
hey not only check for what zontar said also do one thing

put the html head part above the header function where ur redirecting the page.

<HTML>
<head>
...........
</head>

<?
....
header("...");
.....
?>

i guess this is the only problem ur getting

0
 

Expert Comment

by:XIS
ID: 10153667
The header function must be used BEFORE any other HTML code

so header location must be on TOP of the page! !!

try to change order of scripting to get this thing to worK ...
0
 

Expert Comment

by:mxgrogg
ID: 12730706
Zontar's suggestion of not putting "ANYTHING" in front of the <?PHP worked perfectly for me!
-mxgrogg-
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
WSDL Soap Error 12 270
iOS retina Display, HTML Email Signature 5 512
TripAdvisor Widgets on WordPress Websites 10 151
.php tree directory? 5 73
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question