Solved

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

Posted on 2003-12-02
5
5,784 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
jquery validation by class 12 49
Tech Writing Terminology - Pane or Panel? 8 68
Problem to Popup 2 53
Re-position the objects 7 55
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now