Forum Moderators: coopster

Message Too Old, No Replies

Cannot modify header information - headers already sent by

Error message

         

cybertime

8:43 am on May 4, 2006 (gmt 0)

10+ Year Member



When logging in my page is throwing the following
errors.. I think this has to do with
extra blank spaces being in the config.ini php
file..which I can't seem to find:

Warning: Cannot modify header information - headers already sent by (output started at /home/.input/ddole/web.com/login.php:6) in /home/.input/ddole/web.com/login.php on line 164

How do I correct the error?

Thanks

barns101

10:18 am on May 4, 2006 (gmt 0)

10+ Year Member



You can't modify headers after any content has been sent, so trying to set a cookie or doing a header redirect after sending some HTML could be the cause of this problem.

Scally_Ally

10:21 am on May 4, 2006 (gmt 0)

10+ Year Member



could you post some code up to line 164?
every time i have encountered this error it is due to a redirection.. are you doing the same thing?

coopster

1:02 pm on May 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Other ways to troubleshoot this are to use headers_sent [php.net] prior to the header() function to see if any headers have already been sent. If not, you can also [/url=http://php.net/exit]exit()[/url] your script and view the source in the browser to see if there has been anything output. If all you see is blanks in the source, then somewhere in your source code or included files you have blank spaces. Blank spaces are output and have to be removed whether they are outside of <?php?> tags or even if they are within the tags, being printed out like
<?php print ' '; ?>
. Either way, they cannot be there.

If you really can't nail it down you may want to comment out the header() function where it is in your script, make a copy of it and move it higher "up" in your script logic until you get success. At least now you will know that somewhere in between you have issues.

cybertime

3:44 am on May 5, 2006 (gmt 0)

10+ Year Member



Thanks for your assistance. Here is the code:

<?php
require "mywebsite.inc";
require "authentication.inc";
if (!empty($_POST["username"])&&
!empty($_POST["password"]))
{
$user=$_POST["username"];
$pwd=$_POST["password"];
$connection =
mysql_connect($hostname,$g_username,$g_password) or
die("Could not connect");
mysql_select_db($database,$connection)or die
("could not select database");
if (authenticate_user($connection,$user,$pwd))
{
session_start();
header("Location:registration.php");
}
else
{
print "<center> invalid
username/password</center>";
}
}
?>

Scally_Ally

10:16 am on May 5, 2006 (gmt 0)

10+ Year Member



like coopster said, if you print tags or white space etc then this will cause the error.

My money is on it being

else
{
print "<center> invalid
username/password</center>";
}

or something similar within

require "mywebsite.inc";
require "authentication.inc";

scriptmasterdel

10:23 am on May 5, 2006 (gmt 0)

10+ Year Member



Problem should't be in the following code as the header is sent out before this code is executed.

else
{
print "<center> invalid
username/password</center>";
}

I would say the header has been sent out in one of the include files!

require "mywebsite.inc";
require "authentication.inc";

If it will not cause to many problems try placing the two includes below the authentication code (the issue you might have is if one of these files contain db connection settings then you will have to place this at the top of the page).

If not look for echo and/or prints in the files and spaces beetween the php declarations (<?/<?php and?>)

Hope i have helped ;)

Del

taps

11:43 am on May 5, 2006 (gmt 0)

10+ Year Member



A very common problem causing a "headers already sent" is any kind of character in your php-File that stands before the first <?php:

===File starts here===

<?php
//PHP-Stuff

In this case a Space in the first line will cause output to the browser.

dreamcatcher

12:54 pm on May 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The clue is in the error. Its saying the output started in the 'login.php' file. So this is where the problem lies. As previously mentioned, you cannot sent data to the browser before you call the header function.

Do you have your processing info in the login.php file? If so, move it to the very top of the file.

dc

cybertime

11:55 pm on May 10, 2006 (gmt 0)

10+ Year Member



Thank you all for your assistance.

I have been trying to correct the error but have been unsuccessful so far.

Please explain in "layman" language what you mean.

Thanks again.

Here is the code I copied from the website:
<html>
<head>
<title>Agent Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- Fireworks MX Dreamweaver MX target. Created Sat Apr 29 22:47:16 GMT-0400 (Eastern Standard Time) 2006-->
<style type="text/css">
<!--
body {
background-color: #E5E5E5;
margin-top: 5px;
margin-bottom: 5px;
margin-left: 5px;
margin-right: 5px;
}
-->
</style>
<link href="myweb.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>

<script language="javascript">

function checkForm() {
message = "";

if ( (document.main.username.value=="")¦¦(document.main.password.value==""))
{
message+="\n Please enter a username and password.";
}
if (message=="") {
document.main.submit();
return true;
} else
{
alert(message);
return false;
}
}
</script>

<style type="text/css">
<!--
.style1 {color: #333333}
-->
</style>
</head>
<body onLoad="MM_preloadImages('images/rplansOver.gif','images/availsOver.gif','images/featuresOver.gif','images/faqOver.gif','images/supportOver.gif','images/agLoginOver.gif')">
<table width="800" border="0" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC" bgcolor="#FFFFFF" class="main">
<!-- fwtable fwsrc="loginTemplate.png" fwbase="loginTemplate.gif" fwstyle="Dreamweaver" fwdocid = "742308039" fwnested="0" -->
<tr>

</tr>
<tr>
<td rowspan="2" colspan="5"><img name="loginTemplate_r3_c8" src="images/loginTemplate_r3_c8.gif" width="273" height="45" border="0" alt=""></td>
<td colspan="3"><img src="images/loginTemplate_r3_c13.gif" alt="" name="loginTemplate_r3_c13" width="189" height="36" border="0" usemap="#loginTemplate_r3_c13Map"></td>
<td rowspan="2" colspan="2"><img name="loginTemplate_r3_c16" src="images/loginTemplate_r3_c16.gif" width="34" height="45" border="0" alt=""></td>
<td><img src="images/spacer.gif" width="1" height="36" border="0" alt=""></td>
</tr>
<tr>
<td colspan="3"><img name="loginTemplate_r4_c13" src="images/loginTemplate_r4_c13.gif" width="189" height="9" border="0" alt=""></td>
<td><img src="images/spacer.gif" width="1" height="9" border="0" alt=""></td>
</tr>
<tr>
<td rowspan="3" colspan="2"><img name="loginTemplate_r5_c1" src="images/loginTemplate_r5_c1.gif" width="26" height="206" border="0" alt=""></td>
<td colspan="15"><img name="loginTemplate_r5_c3" src="images/loginTemplate_r5_c3.gif" width="774" height="13" border="0" alt=""></td>
<td><img src="images/spacer.gif" width="1" height="13" border="0" alt=""></td>
</tr>
<tr>
<td colspan="15"><img name="loginTemplate_r6_c3" src="images/loginTemplate_r6_c3.gif" width="774" height="3" border="0" alt=""></td>
<td><img src="images/spacer.gif" width="1" height="3" border="0" alt=""></td>
</tr>
<tr>
<td colspan="2"><img name="loginTemplate_r7_c3" src="images/loginTemplate_r7_c3.gif" width="150" height="190" border="0" alt=""></td>
<td colspan="13" valign="top" bgcolor="#FFFFFF">&nbsp;</td>
<td><img src="images/spacer.gif" width="1" height="190" border="0" alt=""></td>
</tr>
<tr>
<td rowspan="4"><img name="loginTemplate_r8_c1" src="images/loginTemplate_r8_c1.gif" width="10" height="371" border="0" alt=""></td>
<td colspan="3"><img name="loginTemplate_r8_c2" src="images/loginTemplate_r8_c2.gif" width="166" height="27" border="0" alt=""></td>
<td><img src="images/loginTemplate_r8_c5.gif" alt="Rate Plans" name="loginTemplate_r8_c5" width="104" height="27" border="0" onMouseOver="MM_swapImage('loginTemplate_r8_c5','','images/rplansOver.gif',1)" onMouseOut="MM_swapImgRestore()"></td>
<td colspan="3"><img src="images/loginTemplate_r8_c6.gif" alt="Availability" name="loginTemplate_r8_c6" width="99" height="27" border="0" onMouseOver="MM_swapImage('loginTemplate_r8_c6','','images/availsOver.gif',1)" onMouseOut="MM_swapImgRestore()"></td>
<td><img src="images/loginTemplate_r8_c9.gif" alt="Features" name="loginTemplate_r8_c9" width="76" height="27" border="0" onMouseOver="MM_swapImage('loginTemplate_r8_c9','','images/featuresOver.gif',1)" onMouseOut="MM_swapImgRestore()"></td>
<td colspan="2"><img src="images/loginTemplate_r8_c10.gif" alt="Frequently Asked Questions" name="loginTemplate_r8_c10" width="80" height="27" border="0" onMouseOver="MM_swapImage('loginTemplate_r8_c10','','images/faqOver.gif',1)" onMouseOut="MM_swapImgRestore()"></td>
<td colspan="2"><img src="images/loginTemplate_r8_c12.gif" alt="Support" name="loginTemplate_r8_c12" width="81" height="27" border="0" onMouseOver="MM_swapImage('loginTemplate_r8_c12','','images/supportOver.gif',1)" onMouseOut="MM_swapImgRestore()"></td>
<td><a href="login.php"><img src="images/loginTemplate_r8_c14.gif" alt="Sales Agents" name="loginTemplate_r8_c14" width="89" height="27" border="0" onMouseOver="MM_swapImage('loginTemplate_r8_c14','','images/agLoginOver.gif',1)" onMouseOut="MM_swapImgRestore()"></a></td>
<td colspan="3"><img name="loginTemplate_r8_c15" src="images/loginTemplate_r8_c15.gif" width="95" height="27" border="0" alt=""></td>
<td><img src="images/spacer.gif" width="1" height="27" border="0" alt=""></td>
</tr>
<tr>
<td colspan="16">&nbsp;</td>
<td><img src="images/spacer.gif" width="1" height="21" border="0" alt=""></td>
</tr>
<tr>
<td rowspan="2">&nbsp;</td>
<td><img name="template_r8_c2" src="images/template_r8_c2.gif" width="1" height="1" border="0" alt=""></td>

<td colspan="14" rowspan="2" align="left" valign="top">
<?php
require "myweb.inc";
require "authentication.inc";
if (!empty($_POST["username"])&&!empty($_POST["password"]))
{
$user=$_POST["username"];
$pwd=$_POST["password"];
$connection = mysql_connect($hostname,$g_username,$g_password) or die("Could not connect");
mysql_select_db($database,$connection)or die ("could not select database");
if (authenticate_user($connection,$user,$pwd))
{
// session_start();
header("Location:registration.php");
}
else
{
print "<center> invalid username/password</center>";
}
}
?>
<form action="login.php" method="post" name="main" id="main" onSubmit="return checkForm();">
<table width="770" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="89">&nbsp;</td>
<td width="152">&nbsp;</td>
<td width="46">&nbsp;</td>
<td colspan="4"><img src="images/loginbanner.gif" width="100" height="25"></td>
<td width="49">&nbsp;</td>
<td width="109">&nbsp;</td>
<td width="7">&nbsp;</td>
<td width="96">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><span class="style1">Username</span></td>
<td colspan="4"><input name="username" type="text" id="username"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><span class="style1">Password</span></td>
<td colspan="4"><input name="password" type="password" id="password"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td width="39">&nbsp;</td>
<td width="46"><input type="submit" value="Login"></td>
<td width="68">&nbsp;</td>
<td width="1">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="4">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="4">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</form></td>






<td><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>
</tr>
<tr>
<td><img name="loginTemplate_r11_c3" src="images/loginTemplate_r11_c3.gif" width="1" height="322" border="0" alt=""></td>
<td><img src="images/spacer.gif" width="1" height="322" border="0" alt=""></td>
</tr>
<tr>
<td colspan="16"><img name="loginTemplate_r12_c1" src="images/loginTemplate_r12_c1.gif" width="799" height="10" border="0" alt=""></td>
<td rowspan="3"><img name="loginTemplate_r12_c17" src="images/loginTemplate_r12_c17.gif" width="1" height="28" border="0" alt=""></td>
<td><img src="images/spacer.gif" width="1" height="10" border="0" alt=""></td>
</tr>
<tr>
<td colspan="16"><img name="loginTemplate_r13_c1" src="images/loginTemplate_r13_c1.gif" width="799" height="17" border="0" alt=""></td>
<td><img src="images/spacer.gif" width="1" height="17" border="0" alt=""></td>
</tr>
<tr>
<td colspan="6"><img name="loginTemplate_r14_c1" src="images/loginTemplate_r14_c1.gif" width="282" height="1" border="0" alt=""></td>
<td colspan="4"><img name="template_r21_c8" src="images/template_r21_c8.gif" width="244" height="1" border="0" alt=""></td>
<td colspan="6"><img name="loginTemplate_r14_c11" src="images/loginTemplate_r14_c11.gif" width="273" height="1" border="0" alt=""></td>
<td><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>
</tr>
</table>
<map name="loginTemplate_r3_c13Map">
<area shape="rect" coords="-4,3,47,24" href="index.php" alt="Myweb Networks">
<area shape="rect" coords="51,-6,126,19" href="#">
<area shape="rect" coords="135,-8,188,19" href="#">
</map>
</body>
</html>

eelixduppy

2:19 am on May 11, 2006 (gmt 0)




Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

In simple terms, you cannot have your header() [us3.php.net] function in the middle of a HTML page. You must find a way to have the header() [us3.php.net] function called before anything gets printed to the screen, including your HTML that you have before your PHP.

eelix