need to redirect url without using the function he

2019-02-23 11:54发布

问题:

I need to redirect my page to another, but I can't use the header function, is there any other way to do it?

What a I need to do is something like this:

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

Thanks

回答1:

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


回答2:

A meta-redirect

    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;
    } 


回答3:

if (test){
  echo "<script type='text/javascript'>
window.onload = function () { top.location.href = '" . $url . "/page.php#contact'; };
</script>";
} else {
   return false
}


回答4:

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;
}

If you're wondering that why I have used both Meta tag and JavaScript to Redirect, then the answer is very simple.

If JavaScript is Disabled in the Browser, then meta tag will redirect the page.