php后端对跳转的封装

php

浏览数:369

2019-1-7

/**
 * 页面跳转
 * $url 跳转地址
 * $time 一段时间后跳转
 */
function app_redirect($url,$time=0,$msg='')
{
    //多行URL地址支持
    $url = str_replace(array("\n", "\r"), '', $url);    
    if (!headers_sent()) {
        // redirect
        if(0===$time&&$msg=="") {
           if(substr($url,0,1)=="/")
           {             
              if(defined("SITE_DOMAIN"))
                 header("Location:".SITE_DOMAIN.$url);
              else
                 header("Location:".$url);
           }
           else
           {
              header("Location:".$url);
           }
            
        }else {
            header("refresh:{$time};url={$url}");   //$time 后跳转 
            echo($msg);
        }
        exit();
    }else {
        $str    = "<meta http-equiv='Refresh' content='{$time};URL={$url}'>";
        if($time!=0)
            $str   .=   $msg;
        exit($str);
    }
}