Posted By

prwhitehead on 04/17/11


Tagged

javascript php redirect


Versions (?)

Safe redirection


 / Published in: PHP
 

If your page has already sent headers to the browser you cant redirect with headers('Location:' . $url);

But you can use the following:

  1. /**
  2. * Usage: safe_redirect('http://www.google.com');
  3. *
  4. */
  5.  
  6. function safe_redirect($url){
  7. ?><script>
  8. <!--
  9. window.location= "<? echo $url; ?>"
  10. //-->
  11. </script>
  12. <?
  13. }

Report this snippet  

You need to login to post a comment.