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

Aaron Uusitalo
Aaron Uusitalo
4,405 Points

Why don't the echo statements before the header method cause redirect failure?

We are warned not to send anything to the browser, even a blank line, lest it be interpreted as a header response and sabotage our redirect.

Why don't the echo statements at the start of our scrip cause this problem?

3 Answers

Andy Goodman
Andy Goodman
14,207 Points

I would like an answer to this question too.

The code clearly shows a number of echo statements in process.php above the header redirect, but the redirect works fine. One of the questions in the next section has an echo statement before the redirect and the correct answer is that you will see the echoed text, but with an error warning for the redirect.

Can someone explain this clearly please?

someone can asnwer this question?


Steven Jackson
Steven Jackson
11,465 Points

They definitely said that even a blank line will cause the re-direct to fail. This looks like an issue with workspaces. I've been using VSCode on this project and the echo statements caused an error. After all an echo creates more than a blank line. Once removed the redirect works properly in the VSCode environment. When I tested it in workspaces the redirect happens regardless of whether or not there is an echo statement. Has to be a bug with workspaces. Even though workspace is pretty amazing for an in-browser app it still has a few bugs. Take the time to set up a dev environment in VSCode or another appropriate IDE. You'll definitely thank yourself later.

Hope this helps!