我有一个函数,它会输出javascript代码来实现页面跳转。在跳转时,
echo 'window.location.href="'.$url.'";';
该功能无法正常工作,只会在屏幕上打印出来。
"window.location.href="./index.php";
我这样使用我的函数:redirect("./index.php");
我的PHP函数如下:
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;
}
}