thinkphp 重定向redirect

 1 /**
 2  * URL重定向
 3  * @param string $url 重定向的URL地址
 4  * @param integer $time 重定向的等待时间(秒)
 5  * @param string $msg 重定向前的提示信息
 6  * @return void
 7  */
 8 function redirect($url, $time=0, $msg='') {
 9     //多行URL地址支持
10     $url        = str_replace(array("\n", "\r"), '', $url);
11     if (empty($msg))
12         $msg    = "系统将在{$time}秒之后自动跳转到{$url}!";
13     if (!headers_sent()) {
14         // redirect
15         if (0 === $time) {
16             header('Location: ' . $url);
17         } else {
18             header("refresh:{$time};url={$url}");
19             echo($msg);
20         }
21         exit();
22     } else {
23         $str    = "<meta http-equiv='Refresh' content='{$time};URL={$url}'>";
24         if ($time != 0)
25             $str .= $msg;
26         exit($str);
27     }
28 }

 

posted @ 2015-02-27 17:08  李照耀  阅读(1882)  评论(0编辑  收藏  举报