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!
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

Chandan K. Sah
Courses Plus Student 12,665 PointsHeader refresh not working
echo "Message has been sent.<br>";
echo "Your will be redirected back to homepage in 5 seconds.<br>";
header("Refresh: 5;url=index.php");
echo "If you are not redirected yet <a href='../index.php'>click here</a>.";
The above code is working on my local machine but when i uploaded the code on live website its not redirecting automatically to my index.php page. I tried on all browsers but its not working. Any suggestions will be highly appreciated..
2 Answers

Alejandro Cavazos
4,250 PointsDo you get any errors? It can be because you have a different php doc root directory. Try adding a / before i dex.php.

Véronique Bellamy
20,810 PointsMaybe it is because you are calling the header after you start sending info to the browser instead of before... Try this instead:
header("Refresh: 5;url=index.php");
echo "Message has been sent.<br />";
echo "You will be redirected back to the homepage in 5 seconds.<br />";
echo "If you are not redirected yet, <a href='../index.php'>click here</a>.";

Chandan K. Sah
Courses Plus Student 12,665 PointsOk, Thanks it worked but i have one more question why the code below is not working same as above?
echo "Message has been sent.<br>";
echo "Your will be redirected back to homepage in 5 seconds.<br>";
echo "If you are not redirected yet <a href='../index.php'>click here</a>.";
header("Refresh: 5;url=../index.php");

Jason Anello
Courses Plus Student 94,610 PointsHi Chandan,
header() has to be called before any html output to the page.