Forum Moderators: coopster

Message Too Old, No Replies

header("location: /thankyou.php"); Can you fix the error?

Cannot modify header information - headers already sent by...

         

King of Bling

11:32 am on Jul 30, 2004 (gmt 0)

10+ Year Member



As an ex-programmer, its amazes me how far one can fall behind in just a few short years.

Now, I am tring to send a user to a 'Thank you' page after they fill out an inquiry form. The form works fine, but throws an error trying to redirect. Any help is greatly apreciated.

ERROR

Warning: Cannot modify header information - headers already sent by (output started at /home/u5/widgets/html/form.php:6) in /home/u5/widgets/html/form.php on line 43

PHP CODE

<?
if($Action=="Request Consultation"){
if($_POST){
//checks for form post
$Recipient = "info@widget.com";
$Subject = "Consulting Request for $FirstName $LastName";
$Headers = "From: Widget World <info@widget.com>\r\n";
$Headers.= "Bcc: info@widget.com\r\n";
$Headers.= "Return-info@widget.com\r\n";
//helps with spam filters
//when building the message string the .= appends the string onto the current content of $Message
// \n is a new line character
$Message.= "Consulting Request courtesy of FWidget World\n";
$Message.= "\n";
$Message.= "First Name: $FirstName\n";
$Message.= "Last Name: $LastName\n";
$Message.= "Email: $Email\n";
$Message.= "Address: $Address\n";
$Message.= "City: $City\n";
$Message.= "State: $State\n";
$Message.= "Zip: $Zip\n";
$Message.= "Phone: $Phone\n";
$Message.= "\n";
mail($Recipient,$Subject,$Message,$Headers);
header("location: /thankyou.php");
//here is the redirect
}
}
?>

Thanks!
KOB

charlier

11:38 am on Jul 30, 2004 (gmt 0)

10+ Year Member



This is usually caused by some unseen space or newline outside the php tags. Take a look at your code with an editor that shows hidden chars and you can probably find it.

You can also use php's output buffering to trap any spurious output. Check out ob_start() in the manual.

King of Bling

12:20 pm on Jul 30, 2004 (gmt 0)

10+ Year Member



My programmer mentioned 'hidden characters' too. But what exactly am I looking for? I've got the PHP code in the <head>, followed by an HTML form in the <body>. I am using Homesite to look for hidden characters, etc.

If only my programmer didn't take a vacation this week :-)

KOB

DanA

1:06 pm on Jul 30, 2004 (gmt 0)

10+ Year Member



You cannot output (echo or html space) anything before header("location: /thankyou.php");
The form must call a php page which will display the message

JasonHamilton

1:37 pm on Jul 30, 2004 (gmt 0)

10+ Year Member



all my php files start with ob_start, this allows me to do header() locations at any time.

jatar_k

4:51 pm on Jul 30, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> I've got the PHP code in the <head>

there's the problem I would imagine. Put the php header code above any html/output sent to the browser and it should work fine.