YII Blog
Yeah Cheung 's Yeah Cheung
yeah
如需合作,请发邮件! (realloveyou@foxmail.com)
热门文章
搜索
计数器
64579
最新留言
链接
最新评论
URL重定向
Dec 24, 2009 12:32:32 AM | Comments(14) | Category:PHP学习 | Tags:URL 重定向
<?php
/**
* URL重定向
*
* @param string $url
* @param int $time
* @param boolean $js
* @param string $msg
public function redirect($url,$time=0, $js = false, $msg='')
{
//多行URL地址支持
$url = str_replace(array("\n", "\r"), '', $url); //如果为多行地址,去除\n \r
if (!headers_sent()) { //判断header头是否已经发送
// redirect
if(0===$time) {
header("Location: ".$url);
}else {
header("refresh:{$time};url={$url}");
echo($msg);
}
exit();
} else if(!$js) { //header头已经发送,并且采用非js方式跳转
$str = "<meta http-equiv='Refresh' content='{$time};URL={$url}'>";
if($time!=0)
$str .= $msg;
exit($str);
} else { //采用js方式跳转
$str = "<script type=\"text/javascript\">
alert('" . $msg . "');
setTimeout(\"location='" . $url . "';\", " . $time . ");";
}
}
?>
/**
* URL重定向
*
* @param string $url
* @param int $time
* @param boolean $js
* @param string $msg
public function redirect($url,$time=0, $js = false, $msg='')
{
//多行URL地址支持
$url = str_replace(array("\n", "\r"), '', $url); //如果为多行地址,去除\n \r
if (!headers_sent()) { //判断header头是否已经发送
// redirect
if(0===$time) {
header("Location: ".$url);
}else {
header("refresh:{$time};url={$url}");
echo($msg);
}
exit();
} else if(!$js) { //header头已经发送,并且采用非js方式跳转
$str = "<meta http-equiv='Refresh' content='{$time};URL={$url}'>";
if($time!=0)
$str .= $msg;
exit($str);
} else { //采用js方式跳转
$str = "<script type=\"text/javascript\">
alert('" . $msg . "');
setTimeout(\"location='" . $url . "';\", " . $time . ");";
}
}
?>