/**
* URL重定向
* @param string $url 重定向的URL地址
* @param integer $time 重定向的等待时间(秒)
* @param string $msg 重定向前的提示信息
* @return void
*/
$url='http://www.baidu.com';
$time=3;
function redirect($url, $time=0, $msg='') {
//多行URL地址支持
$url = str_replace(array("\n", "\r"), '', $url);// $url字符串中换行符\n 回车符\r替换为空
//给出提示信息
if (empty($msg))
$msg = "系统将在{$time}秒之后自动跳转到{$url}!";
//headers_sent — Checks if or where headers have been sent
if (headers_sent()) {//headers_sent未发送时为false
// redirect
if (0 === $time) {
header('Location: ' . $url);//Location定位
} else {
header("refresh:{$time};url={$url}");//refresh重新刷新
echo($msg);
}
exit();
} else {//headers_sent已发送情况 html页面下定时刷新
$str = "<meta http-equiv='Refresh' content='{$time};URL={$url}'>";
if ($time != 0)
$str .= $msg;
exit($str);
}
}
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。