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 Basic PHP Website (2018) Adding a Basic Form Redirecting After a Form Submission

3,428 Points

enable output_buffering in php.ini to permit redirect

I am using a local MAMP installation with my own IDE instead of TeamTreehouse's workspaces. I discovered that the default MAMP installation comes with output_buffering disabled, this will result in a redirect error which causes header("location:thanks.php") to fail. To fix this problem, open php.ini a terminal text editor, then set output_buffering to *on. Save the php.ini file, and restart the MAMP servers. Problem solved!

2 Answers

Andrew Shook
Andrew Shook
31,709 Points

Actually, you probably should not do this since all most ever server I've worked on have this turned off. I think it is also the default config for most php. My guess is that you that you left the echo statements in the file before you called the header function:

echo "<pre>";
$email_body = "";
$email_body .= "Name " . $name . "\n";
$email_body .= "Email " . $email . "\n";
$email_body .= "Details " . $details . "\n";
echo $email_body;
echo "</pre>";

The problem is that you can not send headers to the browser after you start outputting data. You should move the echo statement to below the header() function instead for changing the ini file.

Robert Cooper
Robert Cooper
22,703 Points

Thank you to both Jillian and Andrew. I decided to simply move my echo statements below my header function call and it worked. I'm sure changing the php.ini would also work, but if the default configuration for most php.ini files has output_buffering disabled, then I won't play around with it. Thanks for sharing your findings though since I was having issues with this while using MAMP.

Haha thank you so much!