I have a function which echoes javascript to navigate to a different page. While navigation occurs, the
echo 'window.location.href="'.$url.'";'; 
does not work and simply prints it on the screen.
"window.location.href="./index.php";
I use my function this way: redirect("./index.php");
My php function is as follows
  function redirect($url)
   {    
    if (!headers_sent())
    {    
      header('Location: '.$url);
      exit;
    }
   else
    {      
      echo '<script type="text/javascript">';
      echo 'window.location.href="'.$url.'";';
      echo '</script>';
      echo '<noscript>';
      echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
      echo '</noscript>'; exit;
   }
} 
                Your browser treats the response as plaintext.
Prepend to you response a Content-Type: text/html\n  plus wrap your content inside an <html></html> tag.
Try this way.
<?php
$yourURL="http://www.stackoverflow.com";
echo ("<script>location.href='$yourURL'</script>");
?>
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With