Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to dynamically load/unload User control in ASP.net page? 2 230
Technology stack suggestions 4 68
File names with & character 6 87
Problem to ToolkitScriptManager 2 75
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…
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…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

763 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