简单的php基于curl的反向代理程序

php

浏览数:248

2019-1-8

AD:资源代下载服务
0){
        if(strpos($h,'Content-Length')!==false) continue;
        if(strpos($h,'Transfer-Encoding')!==false) continue;
        if(strpos($h,'Connection')!==false) continue;
        if(strpos($h,'HTTP/1.1 100 Continue')!==false) continue;
        header($h);
    }
}

function replace_html_path($arrMatche)
{   
    $sPath = makeUrl($arrMatche[4]) ;
    if( strtolower($arrMatche[1])=='img' )
    {
        $sPath.= '&bin=1' ;
    }
    
    return "<{$arrMatche[1]} {$arrMatche[2]} {$arrMatche[3]}=\"{$sPath}\"" ;
}

function get_client_header(){
    $headers=array();
    foreach($_SERVER as $k=>$v){
        if(strpos($k,'HTTP_')===0){
            $k=strtolower(preg_replace('/^HTTP/', '', $k));
            $k=preg_replace_callback('/_\w/','header_callback',$k);
            $k=preg_replace('/^_/','',$k);
            $k=str_replace('_','-',$k);
            if($k=='Host') continue;
            $headers[]="$k:$v";
        }
    }
    return $headers;
}

function header_callback($str){
    return strtoupper($str[0]);
}

function parseHeader($sResponse){
    list($headerstr,$sResponse)=explode("\r\n\r\n",$sResponse, 2);
    $ret=array($headerstr,$sResponse);
    if(preg_match('/^HTTP\/1\.1 \d{3}/', $sResponse)){
        $ret=parseHeader($sResponse);
    }
    return $ret;
}

function gtRootUrl()
{
//缓存结果,同一个request不重复计算
 static $gtrooturl;
 if(empty($gtrooturl)){
    // Protocol
    $s = !isset($_SERVER['HTTPS']) ? '' : ($_SERVER['HTTPS'] == 'on') ? 's' : '';
    $protocol = strtolower($_SERVER['SERVER_PROTOCOL']);
    $protocol = substr($protocol,0,strpos($protocol,'/')).$s.'://';
    // Port
    $port = ($_SERVER['SERVER_PORT'] == 80) ? '' : ':'.$_SERVER['SERVER_PORT'];
    // Server name
    $server_name = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'].$port : getenv('SERVER_NAME').$port;
    // Host
    $host = isset($_SERVER['HTTP_HOST']) ? strtolower($_SERVER['HTTP_HOST']) : $server_name;

     $gtrooturl=$protocol.$host.$_SERVER['REQUEST_URI'];
    }
        return $gtrooturl;
}

// close cURL resource, and free up system resources
curl_close($aAccess);
echo $sResponse ;