Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


PHP error: Cannot modify header information - headers already sent....

I'm using what I learned in the tutorial for the Contact.php form to create a form for a friend. She has an HTML site with a lot of 'junk' in the top for navigation, so I've left that and worked the PHP around it. I got it working fine until you submit the form, then it gives an error (Warning: Cannot modify header information - headers already sent by (output started at /home/ncaca1/public_html/registration/071213.php:6) in /home/ncaca1/public_html/registration/071213.php on line 85) instead of redirecting to show the 'thank you for your submission' message.

Here is the code: http://codetidy.com/5683/

Thank you for any help!

7 Answers

Apparently I just needed to 'say it out loud' to be able to figure it out :) I moved the PHP at the top to the very top above the <html> tag and it works now. Thanks anyway!

Randy Hoyt
Randy Hoyt
Treehouse Guest Teacher

That's exactly right! You have to set headers before you have any HTML.

I win a cookie! Love your tutorial btw. Excellent tool!!

Haha! Yea! My fav kind too :)

I need to give my cookie back :( I just uploaded it to their server, and I'm back to getting the error. It worked fine on my local server, but it's not working on theirs. Any thoughts?!

sigh Sorry for spamming the thread. I still had it like this: <!DOCTYPE HTML> <?php> **** code **** ?>

So moved it once again...above the <!DOCTYPE HTML> too and it is working on their server as well now. I get to keep the cookie :)