headers already sent

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Live24x7
Forum Contributor
Posts: 194
Joined: Sat Nov 19, 2011 9:32 am

headers already sent

Post by Live24x7 »

My code is using the header("Location:rthankyou.php"); to redirect after user has filled a form.

This is working extremely well in the lamp/wamp server but is generating error on actual server.

Error msg on actual server:
Cannot modify header information - headers already sent by (output started at /home/****/public_html/easyblood.info/header.php:5) in
/home/****/public_html/easyblood.info/rform.php on line 110
line 5 code:

Code: Select all

include_once ('header.php'); 

Code: Select all

.

	<?php if (isset($_POST['submit'])) 
				{ 		
                                      //some code here
				if (empty($problem))  //if no problems insert into db and redirect to thankyou page
				{ 				// Insert into DB after sanitization
                                     require_once ('connect.php');
					mysql_query("INSERT INTO pd VALUES ('$rname', '$rgender','$ryob', '$rmn','$rlocation', '$remail','$rdate' )"); 
				$ToEmail = $remail; $EmailSubject = 'Your Membership details'; 
				$mailheader = "From: mE.\r\n"; 	$mailheader .= "Reply-To: $remail.\r\n"; $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
				$MESSAGE_BODY = "<br> Congratulations ! <br><br> Your are now a Member.<br>"; 
				mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");*/
				header("Location:rthankyou.php"); die(); // this is line 110
 }
}

?>


i read somewhere that headers already sent" error is usually caused by having white space before or after the opening and closing PHP tags (<?php . . . ?>).
I have no such error

Any pointers on what could be wrong.? and why is it working in wamp and not on server ?
Live24x7
Forum Contributor
Posts: 194
Joined: Sat Nov 19, 2011 9:32 am

Re: headers already sent

Post by Live24x7 »

update: i used a javascript redirection inaead of php and its working fine. However i would still love to retuurn to using a php redirect.

thanks
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: headers already sent

Post by Christopher »

The "headers already sent error" usually occurs when some output is sent to the browser before reaching the header() call. Anything outside the PHP tags will cause output to be sent. This is often spaces or returns before or after the <?php and ?> tags -- these can be difficult to find.
(#10850)
Post Reply