For long I always thought that header function will only work when there is nothing rendered before the header call.
But recently I discovered(ofcorse with help of google) that we can render anything before the header call and still redirect the page.
Normal Usage with error is
echo "This will give error"
header("location:http://www.yahoo.com");
echo "This will NOT give error";
header("refresh:0; url:http://www.yahoo.com");
Here refresh:0 means the page will load after 0 seconds(which is instantly).
Basically this can be used when we want to have delay the page loading say we want to load yahoo after 2 seconds.
In this case the code will be
header("refresh:2; url:http://www.yahoo.com");
So start using this header call and redirect the page anytime during page execution.
No comments:
Post a Comment