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!
How would I do a redirect on a contact form after a user successfully submits the form. I tried doing a header Location:, but I received that error. Basically I don't want to display just the Success! text, I want to redirect. Here is my code:
You cannot echo, or send any output, before you call the header() function. Any output, even spaces between/before/after <?php ?> tags will cause PHP to send the HTTP headers. Once that happens you cannot call header() to send more headers.
arborint wrote:Any output, even spaces between/before/after <?php ?> tags will cause PHP ...
Actually, that is not true. You can absolutely have space between the <?php and ?>. You can have an infinite number of lines of code. Just make sure you do not output anything [i.e. - echo] to the screen. From php.net:
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.