Redirecting?

After my contact form is filled out why is my redirection code,


header("Refresh: 3;url=http://www.google.com/");

producing this
Warning: Cannot modify header information - headers already sent by (output started at /home/fixmy1/public_html/masterasp/contact.php:13) in/home/fixmy1/public_html/masterasp/contact.php on line 42

because you have already sent output to the page, you can’t have any output on the page prior to your header() statement. So no echo, print, or text outside of php tags.

so, the only way I can use that statement is if its the first thing on my page?

the only way you can use header() and setcookie (for that matter) is if you have not started any output yet. You can have other PHP code above it, validation, emailing the form contents, writing/reading to a database, etc, but you can’t have output.

Think of it this way:

header() is a command to the browser to tell it to redirect to somewhere else. If you have output, the browser will begin its render process and won’t acknowledge any commands, because it is past that stage and in the stage of drawing the output to the page for the user to see.