Need to redirect url without using function header

I need to redirect my page to another, but I cannot use the header function, is there any other way to do this?

What I need to do is something like this:

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

thanks

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

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, ie immediately. } else { return false; } 
+5
source
 if (test){ echo "<script type='text/javascript'> window.onload = function () { top.location.href = '" . $url . "/page.php#contact'; }; </script>"; } else { return false } 
+1
source
 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 why I used the Meta tag and JavaScript to redirect , then the answer is very simple.

If JavaScript is disabled in the browser, the meta tag redirects the page.

+1
source

Source: https://habr.com/ru/post/1496766/


All Articles