Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
99
rated 0 times [  102] [ 3]  / answers: 1 / hits: 79249  / 12 Years ago, wed, april 11, 2012, 12:00:00

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

More From » php

 Answers
26

Your browser treats the response as plaintext.



Prepend to you response a Content-Type: text/htmln plus wrap your content inside an <html></html> tag.


[#86304] Tuesday, April 10, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bryonk

Total Points: 161
Total Questions: 116
Total Answers: 107

Location: Albania
Member since Sun, Nov 22, 2020
4 Years ago
bryonk questions
;