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.&...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 ); } } ?> |
|
|||
|
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> |
|
|||
|
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> > > |
![]() |
| Thread Tools | |
| Display Modes | |
|
|