function redirect($url,$time=0,$msg=''){
    //多行URL地址支持
    //去除多行url之间的换行
    //范例1,看看不用str_replace和用的区别
    $url=str_replace(array("\n","\r"),'',$url);
    if(empty($msg))
        $msg = "系统将在{$time}秒之后自动跳转到{$url}!";
    //如果报头未发送
    if(!headers_sent()){
        if(0===$time){
            header("Location".$url);
        }else{
            //$time秒后跳转到$url
            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="http://www.baidu.com";
$msg="lemon";
redirect($url,$time=1,$msg)



//范例1
/*$url="http://www.baidu.com
http://www.sina.com
";
$url = str_replace(array("\n", "\r"), '', $url);
print_r($url);

 

 

posted on 2012-12-07 09:32  睡着的糖葫芦  阅读(259)  评论(0编辑  收藏  举报