php的URL重定向函数

技术文章 2014年6月9日 6.78K

// URL重定向

function redirect($url, $time=0, $msg=”) {

//多行URL地址支持

$url = str_replace(array(“\n”, “\r”), ”, $url);

if ( empty($msg) )

$msg = “系统将在{$time}秒之后自动跳转到{$url}!”;

if (!headers_sent()) {

// redirect

if (0 === $time) {

header(‘Location: ‘ . $url);

} else {

header(“refresh:{$time};url={$url}”);

echo($msg);

}

exit();

} else {

$str = “<meta http-equiv=’Refresh’ content='{$time};URL={$url}’>”;

if ($time != 0)

$str .= $msg;

exit($str);

}

}

 

//url重定向2
function redirect($url) {

echo “<script>”.
“function redirect() {window.location.replace(‘$url’);}\n”.
“setTimeout(‘redirect();’, 1000);\n”.
“</script>”;
exit();

}

 


关注微信公众号『PHP学习网

第一时间了解最新网络动态
关注博主不迷路~

PHP学习网:站内收集的部分资源来源于网络,若侵犯了您的合法权益,请联系我们删除!
分享到:
赞(0)

文章评论

您需要之后才可以评论
0点赞 0评论 收藏 QQ分享 微博分享

PHP学习网

PHP学习网