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 trialAb Eds
8,278 Pointswhat should it do , shouldn't it redirect to the new file.php
what does the following output
<?php
echo "Hello world!";
header("Location: new file.php");
//<< shouldn't this redirect to the content o the new file.php because they are redirected to new file.php
it says here wrong answer why?
2 Answers
Greg Kaleka
39,021 PointsHi Ab,
Sending information to the browser (including an echo statement), and then setting a header will always result in a warning and not actually set that header. If you pop back to the video starting at 4:22, Alena explains this. Essentially, sending anything to the browser will automatically set the header for that response, and you can't set the header twice. From the video:
Remember, we need to make sure that we don't send anything to the browser before the redirect. Even a blank line at the beginning of the file is a header response, and will cause the redirect to fail.
Hope that clears things up!
Cheers
-Greg
Ab Eds
8,278 Pointsits a typo yes i just edited it and fixed it ,
but still i don't know why the answer is not what i expected
Ben Payne
1,464 PointsBen Payne
1,464 PointsNot sure if it's just a typo but you have a capital R in the header function declaration.