Headers already sent?

This is a discussion on Headers already sent? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hello. I just wondered if anyone has experienced this error before? "Warning: Cannot modify header information - headers already sent.&...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-23-2004
John
 
Posts: n/a
Default Headers already sent?

Hello.

I just wondered if anyone has experienced this error before?

"Warning: Cannot modify header information - headers already sent."

Thanks for any help

John


Reply With Quote
  #2 (permalink)  
Old 10-23-2004
John
 
Posts: n/a
Default Re: Headers already sent?

On Fri, 22 Oct 2004 22:34:14 -0700, A strange species called "Michael
Vilain <vilain@spamcop.net>" wrote:

>In article <hcojn0d4pas4fpgsg8k2fo9uvv6o7rb2bv@4ax.com>,
> John <duki@dafiqak.com> wrote:
>
>> I just wondered if anyone has experienced this error before?
>> "Warning: Cannot modify header information - headers already sent."

>
>Yes. It's a common mistake if you send anything to the browser then
>send a header(). Use headers_send() to test if this is true and fix
>your logic.


How do I use this headers_send() to test? I am not so advanced.

The error it says is on line 52

This is line 52:

header("Location: ". $MM_redirectLoginSuccess );

It doesn't look like it is sending anything further? It is just
registering the session variables and then redirecting.

I put the whole php part of the page at the bottom. I had the same
problem in my registration page but solved it by deleting whitespace.
I tried doing the same with this file but I still have the error.

John



<?php
session_start();
// *** Validate request to login to this site.
//session_start();
?>

<?php
// Report all PHP errors (bitwise 63 may be used in PHP 3)
error_reporting(E_ALL);
?>

<?php require_once('Connections/conn_newland.php'); ?>
<?php
// *** Validate request to login to this site.


$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($accesscheck)) {
$GLOBALS['PrevUrl'] = $accesscheck;
session_register('PrevUrl');
}

if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['pwd'];
$MM_fldUserAuthorization = "userGroup";
$MM_redirectLoginSuccess = "index.php";
$MM_redirectLoginFailed = "login_failed.php";
$MM_redirecttoReferrer = true;
mysql_select_db($database_conn_newland, $conn_newland);

$LoginRS__query=sprintf("SELECT username, pwd, userGroup FROM
tbl_users WHERE username='%s' AND pwd='%s'",
get_magic_quotes_gpc() ? $loginUsername :
addslashes($loginUsername), get_magic_quotes_gpc() ? $password :
addslashes($password));

$LoginRS = mysql_query($LoginRS__query, $conn_newland) or
die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {

$loginStrGroup = mysql_result($LoginRS,0,'userGroup');

//declare two session variables and assign them
$GLOBALS['MM_Username'] = $loginUsername;
$GLOBALS['MM_UserGroup'] = $loginStrGroup;

//register the session variables
session_register("MM_Username");
session_register("MM_UserGroup");

if (isset($_SESSION['PrevUrl']) && true) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: ". $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>


Reply With Quote
  #3 (permalink)  
Old 10-23-2004
Chris Martin
 
Posts: n/a
Default Re: Headers already sent?

Here's some info on the headers already sent error.

http://www.parseerror.com/php/headers_already_sent.php

From what I know of this error (I've gotten it before, sadly, but fixed it
by moving my headers to the top of the page) is that the headers come first!
Not really first, but before any other output. So you can have a 'header'
further down in the page, but it has to be before other output..

It looks like all your code is PHP in that file, why do you use seperate PHP
tags? if you opened one PHP tag at the beginning and closed the same tag at
the very end, (if that's possible for you), maybe it will read all the
headers as one chunk and accept it.

Another weird thing about headers is they hate white space.. so your first
"<?php", make sure there isn't a blank line or a space before it.

Just some thoughts to try, still learning the basics myself!

~Chris

<snip>


Reply With Quote
  #4 (permalink)  
Old 11-18-2004
Guy Martin
 
Posts: n/a
Default Re: Headers already sent?

Not only that, but make sure that there is no white space between your
php tags, and there is no white space at the end of your file.

Go to the last ?> and put the cursor directly after the ">", then select
everything after it. There may only be a space or new line, but delete
this as this also induces the headers already sent error.

Chris Martin wrote:
> Here's some info on the headers already sent error.
>
> http://www.parseerror.com/php/headers_already_sent.php
>
> From what I know of this error (I've gotten it before, sadly, but fixed it
> by moving my headers to the top of the page) is that the headers come first!
> Not really first, but before any other output. So you can have a 'header'
> further down in the page, but it has to be before other output..
>
> It looks like all your code is PHP in that file, why do you use seperate PHP
> tags? if you opened one PHP tag at the beginning and closed the same tag at
> the very end, (if that's possible for you), maybe it will read all the
> headers as one chunk and accept it.
>
> Another weird thing about headers is they hate white space.. so your first
> "<?php", make sure there isn't a blank line or a space before it.
>
> Just some thoughts to try, still learning the basics myself!
>
> ~Chris
>
> <snip>
>
>

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:48 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0