I find PHP better than JS when redirecting, though mainly because I don't know JSLixas wrote:i guess it's the best way to redirect. but sometimes php is just not able to do that. so in this case JS will do the job
JavaScript redirection can be done in 3 ways
Moderator: Lixas
[PHP]function redirect($location)// Redirect browser using the header function if it fails, use javascriptFlipper3 wrote:In what cases is PHP not able to do that?
{
if(!headers_sent())
{
header("Location: " . $location);
exit;
}
else
{
echo "
<html>
<head>
<title>Redirecting...</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1257\">
</head>
<body>
<script type='text/javascript'>****.location.href='".$location ."'</script>
You are being redirected to $location. Please <a href=\"$location\">**** this link</a>if you are not being redirected in 5 seconds!
</body></html>";
exit;
}
}[/PHP]
header("Location: " . $location); function may fail if there is send some text to user's browser, it may be a part of page or just a simple single space