php实现反向代理代码
代码语言:php
所属分类:通讯
代码描述:php实现反向代理代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<?php set_time_limit(60); if( !defined('__DIR__') ) { define('__DIR__',dirname(__FILE__)) ; } $_REQUEST['url'] =gtRootUrl(); //改成网站正式服务器ip $ip= '127.0.0.1'; $aAccess = curl_init() ; // -------------------- // set URL and other appropriate options curl_setopt($aAccess, CURLOPT_URL, $_REQUEST['url']); curl_setopt($aAccess, CURLOPT_HEADER, true); curl_setopt($aAccess, CURLOPT_RETURNTRANSFER, true); curl_setopt($aAccess, CURLOPT_FOLLOWLOCATION, false); curl_setopt($aAccess, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($aAccess, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($aAccess, CURLOPT_TIMEOUT, 60); curl_setopt($aAccess, CURLOPT_BINARYTRANSFER, true); //curl_setopt($aAccess, CURLOPT_HTTPPROXYTUNNEL, 0); curl_setopt($aAccess,CURLOPT_PROXY,$ip.':80'); //curl_setopt($aAccess,CURLOPT_PROXY,'127.0.0.1:8888'); if(!empty($_SERVER['HTTP_REFERER'])) curl_setopt($aAccess,CURLOPT_REFERER,$_SERVER['HTTP_REFERER']) ; $headers=get_client_header(); curl_setopt($aAccess,CURLOPT_HTTPHEADER,$headers) ; if( $_SERVER['REQUEST_METHOD']=='POST' ) { curl_setopt($aAccess, CURLOPT_POST, 1); curl_setopt($aAccess, CURLOPT_POSTFIELDS, http_build_query($_POST)); } // grab URL and pass it to the browser $sResponse = curl_exec($aAccess); list($headerstr,$sResponse)=parseHeader($sResponse); $headarr= explode("\r\n", $headerstr); foreach($headarr as $h){ if(strlen($h)>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 "&.........完整代码请登录后点击上方下载按钮下载查看
网友评论0