Solved

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

Posted on 2003-12-02
5
5,789 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
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…

734 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