FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

How to write redirection sentence in PHP?

 


Rising
In ASP,I can write "response.redirect URL" to redirect to a URL.How to do it in PHP?
Aelita
header ('Location: the page you want')
This is all you need to do for one way to redirect. Hope this help you out
n0obie4life
Code:
function redirect($filename) {
   if (!headers_sent())
       header('Location: '.$filename);
   else {
       echo '<script type="text/javascript">';
       echo 'window.location.href="'.$filename.'";';
       echo '</script>';
       echo '<noscript>';
       echo '<meta http-equiv="refresh" content="0;url='.$filename.'" />';
       echo '</noscript>';
   }
}


Usage -
Code:
redirect("http://www.google.com");
Rising
Aelita wrote:
header ('Location: the page you want')
This is all you need to do for one way to redirect. Hope this help you out
Thanks! It's the PHP way to handle the redirection.
Rising
n0obie4life wrote:
Code:
function redirect($filename) {
   if (!headers_sent())
       header('Location: '.$filename);
   else {
       echo '<script type="text/javascript">';
       echo 'window.location.href="'.$filename.'";';
       echo '</script>';
       echo '<noscript>';
       echo '<meta http-equiv="refresh" content="0;url='.$filename.'" />';
       echo '</noscript>';
   }
}


Usage -
Code:
redirect("http://www.google.com");
Thanks! I think it's the HTML way to solve the problem.It works! Thanks very much!
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.