redirect 重定向的通用语法为:redirect(url,params=array(),delay=0,msg='')

用法:

protected function redirect($url,$params=array(),$delay=0,$msg='') {

$url = U($url,$params);

redirect($url,$delay,$msg);

}

源码:参见框架内置的functions.php文件



​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重定向​

​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​​​ ​​{ ​​​​//否则就发送 meta 标记,含义同上​

​$str​​​ ​​= ​​​​"<meta http-equiv='Refresh' content='{$time};URL={$url}'>"​​​​;​

​if​​​ ​​(​​​​$time​​​ ​​!= 0)​

​$str​​​ ​​.= ​​​​$msg​​​​;​

​exit​​​​(​​​​$str​​​​);​

​}​

​}​





​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​​​​);​

​}​

​}​