Page 2 of 2
					
				
				Posted: Wed Jan 30, 2008 4:30 am
				by sahilamin
				Lixas 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
I find PHP better than JS when redirecting, though mainly because I don't know JS 

 
			 
			
					
				
				Posted: Fri Feb 01, 2008 3:36 pm
				by Lixas
				Flipper3 wrote:In what cases is PHP not able to do that?
[PHP]function redirect($location)// Redirect browser using the header function if it fails, use javascript
{
    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
 
			 
			
					
				
				Posted: Mon Aug 18, 2008 7:44 am
				by Alwahsh
				thanks for sharing this but I think it's nice to redirect using the cpanel !