├── .htaccess ├── README.md └── index.php /.htaccess: -------------------------------------------------------------------------------- 1 | RewriteEngine On 2 | RewriteCond %{REQUEST_FILENAME} !-f 3 | RewriteCond %{REQUEST_FILENAME} !-d 4 | RewriteRule ^ index.php [QSA,L] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HProxy-PHP 2 | HProxy powered by PHP 3 | 4 | # 使用教程 5 | 1.登录Github,先将这个 repo Fork到自己的帐号里(右上角) 6 | 7 | 2.打开[heroku](https://www.heroku.com/), 点击[注册(Sign Up)](https://signup.heroku.com/),注册一个帐号 8 | 9 | 3.登陆之后默认就在[app面板](https://dashboard.heroku.com/apps),点击右上角的News-Create new app   10 | 11 | 4.然后输入名字,第二个选项是服务器所在位置,默认的美国不用改 12 | 13 | 5.创建好之后,默认应该打开的是Deploy(部署) 选项卡,在Deployment method处选Github,登录并关联自己的Github帐号 14 | 15 | 6.在Connect to GitHub这一栏,搜索HProxy,然后选中这个repo 16 | 17 | 7.在最下面的Manual deploy这一栏,选中master,然后点Deploy Branch 18 | 19 | 8.完成,接下来只要在应用的HProxy设置中填上这个app的地址(默认为https://<你填的名字>.herokuapp.com/) 20 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | $value){ 8 | if($key=="Host" || $key=="User-Agent") 9 | continue; 10 | $headerArray[] = $key.":".$value; 11 | } 12 | $collectuseragent = "KuaiYanKanShu Spider+(+http://www.kuaiyankanshu.net/about/spider.html)"; 13 | $ch = curl_init($originUrl); 14 | //print_r($headerArray); 15 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray); 16 | curl_setopt($ch, CURLOPT_HEADER, true); 17 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 18 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 19 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); 20 | curl_setopt($ch, CURLOPT_USERAGENT, $collectuseragent); 21 | curl_setopt($ch, CURLOPT_ENCODING, 'gzip'); 22 | curl_setopt($ch, CURLOPT_POST, $post); 23 | if($post) 24 | curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST); 25 | $response = curl_exec($ch); 26 | $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); 27 | $responseHeaders = substr($response, 0, $headerSize); 28 | $html = substr($response, $headerSize); 29 | curl_close($ch); 30 | 31 | //echo $responseHeaders; 32 | $headerArray = explode("\r\n", $responseHeaders); 33 | $matched = false; 34 | $charset = "utf-8"; 35 | foreach($headerArray as $header){ 36 | if(preg_match('/charset.*?([\w-]+)/i', $header, $matches)){ 37 | $charset = $matches[1]; 38 | $matched = true; 39 | } 40 | } 41 | if(!$matched && preg_match('/charset.*?([\w-]+)/i', $html, $matches)){ 42 | $charset = $matches[1]; 43 | } 44 | header( "Content-Type:text/plain; charset=".$charset); 45 | echo $html; 46 | }else{ 47 | header( "Content-Type:text/plain;charset=utf-8"); 48 | foreach($headers as $key => $value) { 49 | echo "\r\n"; 50 | } 51 | } 52 | 53 | function get_all_headers() { 54 | $headers = array(); 55 | 56 | foreach($_SERVER as $key => $value) { 57 | if(substr($key, 0, 5) === 'HTTP_') { 58 | $key = substr($key, 5); 59 | $key = strtolower($key); 60 | $key = str_replace('_', ' ', $key); 61 | $key = ucwords($key); 62 | $key = str_replace(' ', '-', $key); 63 | $headers[$key] = $value; 64 | } 65 | } 66 | 67 | return $headers; 68 | } 69 | ?> --------------------------------------------------------------------------------