<?php !defined('APP_DIR') ? die('acceess not defined') : '';
/**
 * http请求相关内容
 *
 */
class url{
    /**
     * 获取页面当前强求的URL
     *
     * @return string
     */
    static public function current_url(){
        $url = '/error_404';
        if ( isset($_SERVER['SCRIPT_URL']) ) {
            $url = $_SERVER['SCRIPT_URL'];
        /*}elseif (isset($_SERVER['PATH_INFO'])){
            $url = $_SERVER['PATH_INFO'];*/
        }elseif( isset($_SERVER['REQUEST_URI']) ) {
            $arr = explode('?',$_SERVER['REQUEST_URI']);
            $url = $arr[0];
        }elseif ( isset($_SERVER['PHP_SELF']) ){
            $url = $_SERVER['PHP_SELF'];
        }
        if (substr($url,strlen($url)-1,1) == '/') {
        	$url = substr($url,0,strlen($url)-1);
        }
        return $url;
    }
    
    static public function last_url($default='/'){
        return isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $default;
    }
    
    /**
     * 获取当前请求的域名
     *
     * @return unknown
     */
    static public function host(){
        return $_SERVER['HTTP_HOST'];
    }
    
    /**
     * 页面跳转
     *
     * @param string $url
     * @param int $status
     */
    static public function redirect($url, $status = '302'){
        $header_status = array(
            '301' => 'HTTP/1.1 301 Moved Permanently',
        );
        if ( key_exists($status,$header_status) ) {
        	header($header_status[$status]);
        }
        header("Location: $url");
        exit();
    }
}
?>