FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free 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!
Related topics
Sig Images
script backup database
[SUGGESTION] Crack down on spelling, grammar and spam
Php and Other Wonderful Newbie Stories for Help.
Crash course in PHP and MYSQL
Idea for post-apocalypse survival type game.
Some cPanel and cvsquestions and stuff
234 productions
Cloaking Problems...
Which Portal System better?
How to load external text and html?
.htaccess -- redirecting an I.P. range
Looking for a PHP Scriptor
301 redirection in PHP and .htaccess
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-2011 Frihost, forums powered by phpBB.