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 trialZack Klinger
17,622 PointsWarning: Cannot modify header information - headers already sent by (output... [SOLVED]
Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/contact.php:2) in /Applications/MAMP/htdocs/contact.php on line 5
in this code:
<!-- this takes the information from the POST method and puts it into a variable called &email_body and then sends the user to the contact.php page with status=thanks. --> <?php error_reporting(-1); ini_set('display_errors','On'); ... header("Location: contact.php?status=thanks"); ...
Is failing because of the HTML call in my comments sections happening before header() is called.
source: http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php
"" No output before sending headers!
Functions that send/modify HTTP headers must be invoked before any output is made. summary ⇊ Otherwise the call fails:
Warning: Cannot modify header information - headers already sent (output started at script:line) Some functions modifying the HTTP header are:
header / header_remove session_start / session_regenerate_id setcookie / setrawcookie Output can be:
Unintentional:
Whitespace before <?php or after ?> The UTF-8 Byte Order Mark specifically Previous error messages or notices ""
Zack Klinger
17,622 PointsZack Klinger
17,622 PointsThat's funny, it ignored the !-- in my first post. If you call !-- (an HTML comment) before your PHP code, the header() function cannot be invoked.