Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Simple PHP Application Adding a Contact Form Redirecting After a Form Submission

header() method has no effect

I've tried to use different examples of header("Location: name.php");, but nothing seems to work. I still get the contact-process.php page. What might be wrong?

3 Answers

Can you post your code?

https://teamtreehouse.com/forum/posting-code-to-the-forum

header doesn't work if you output any html before it. Having a blank line before your opening php tag is considered output and would be one cause on why this is not working.

I figured out the problem: I had an echo statement right before the header() function. I'm really new to PHP, so that didn't seem wrong at first :) Thank all of you for help! I really appreciate it.

Samiruddin Syed
Samiruddin Syed
3,136 Points

Th header function works only if you write it correctly, notice the "L" in your header location is in uppercase letters. It should be header("location:name.php");

Try to avoid spaces where they aren't required :)

Hope that helps.

The examples on this page http://www.php.net/manual/en/function.header.php show it with both an uppercase 'L' and a space after the ':'

Samiruddin Syed
Samiruddin Syed
3,136 Points

Can you post the code of the page here ?