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


Milos Stankovic
Milos Stankovic
15,691 Points

Redirection to the thanks.php page is not working

On my localhost (php 5.6), the redirection to the thanks.php page is not working. I got error:

"headers already sent..."

This is fixed when I delete all echo lines in process.php file.

Check this...

2 Answers

Hi Milos,

Which course is this from and can you link to the video you're currently on?

This is the expected behavior if output buffering is turned off. Header redirects will not work if you have any kind of output to the page before the header redirect. The echo statements you have as well as a blank line at the top of the file before the opening php tag would all count as output to the page and stop a redirect from happening.

If output buffering is turned on then the header redirect would still work because the output is buffered instead of being sent.

You likely have output buffering turned off in your local installation. The php environment within workspaces has output buffering turned on. So it should work in workspaces even with the echo statements in place.

If you'd like to see what your output_buffering directive is set to you can add phpinfo(INFO_CONFIGURATION); to the top of your page and it should give you a table of directives and their values.

Look for output_buffering and see what the value is. If it's 'no value' or 'off' or maybe even 0 then it means output buffering is turned off.

Milos Stankovic
Milos Stankovic
15,691 Points

Hi Jason,

Thank you for the suggestion. When I enabled output_buffering in php.ini, now page redirects even with echo commands uncommented.


Cheers, Milos