Zijun Liao13,409 Points
Send string to browser before redirection
In this video, Alena mentioned that we should not send any string to the browser before the redirection, otherwise it causes an error.
I just wondering what does sending a string to browser means, like echo anything? I tried echo "XXX", but it still works as usual.
Ricardo Vermaat150 Points
When you redirect using a header() function you cannot already have headers sent to the browser prior to this function.
echo 'Hello World!'; header('Location: teamtreehouse.com');
Will result in a warning:
PHP Warning: Cannot modify header information - headers already sent by (output started at / home/treehouse/workspace/index.php:2) in /home/treehouse/workspace/index.php on line 3
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.