需要在不使用函数头的情况下重定向url


need to redirect url without using the function header

我需要将我的页面重定向到另一个页面,但我不能使用header函数,有其他方法吗?

我需要做的是这样的事情:

if (test){
   ---do something---
   redirect
} else {
   return false
}

感谢

if (test){
   ---do something---
   die("<script>location.href = 'http://www.google.com'</script>");
} else {
   return false;
}

元重定向

    if (test){
       //do something
       echo '<META HTTP-EQUIV="Refresh" Content="0; URL=yourpage.php">';//This causes the browser to open the new page after 0 seconds, i.e immediately.
    }  else {
       return false;
    } 
if (test){
  echo "<script type='text/javascript'>
window.onload = function () { top.location.href = '" . $url . "/page.php#contact'; };
</script>";
} else {
   return false
}
if (test){
   ---do something---
  $URL="http://yourwebsite.com/";
  echo '<META HTTP-EQUIV="refresh" content="0;URL=' . $URL . '">';
  echo "<script type='text/javascript'>document.location.href='{$URL}';</script>";
} else {
   return false;
}

如果你想知道为什么我同时使用Meta标签和JavaScript来重定向,那么答案很简单。

如果浏览器中禁用了JavaScript,则元标记将重定向页面。