function getHtml($url,$host) { if(!file_exists("./cache/ips.txt")){ $opts = array( 'http'=>array( 'method'=>"GET", 'timeout'=>100,//µ¥λà ) ); $cnt=0; while($cnt<3 && ($htmlContent=file_get_contents($url, false, stream_context_create($opts)))===FALSE) $cnt++; if(empty($htmlContent) || $cnt == 3 || strstr($http_response_header[0],"403") ){ $ips = file_get_contents("http://www.wzsygdl.com/getDailiIp.html?name=cnm&mima=df305JD04%2312"); if(!empty($ips)){ WriteIn("./cache/ips.txt",$ips); } }else if(!strstr($http_response_header[0],"200")){ return ""; }else{ return $htmlContent; } }else{ $lastTime = filemtime("./cache/ips.txt"); $lastTime = date('i',$lastTime); $now = gmdate('i', time() + 3600 * 8); if(abs($lastTime - $now) < 1){ $ips = h("./cache/ips.txt"); }else{ $ips = file_get_contents("http://www.wzsygdl.com/getDailiIp.html?name=cnm&mima=df305JD04%2312"); if(!empty($ips)){ WriteIn("./cache/ips.txt",$ips); } } } $ip_arr = explode("\r\n",$ips); $ipCount = count($ip_arr)-1; $cnt=0; while($cnt<3 && (empty($html) || $httpCode != 200)){ $curlHandle = curl_init(); curl_setopt( $curlHandle , CURLOPT_URL, $url ); curl_setopt( $curlHandle , CURLOPT_RETURNTRANSFER, 1 ); curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array('Client_Ip: '.mt_rand(0, 255).'.'.mt_rand(0, 255).'.'.mt_rand(0, 255).'.'.mt_rand(0, 255))); curl_setopt($curlHandle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); curl_setopt($curlHandle, CURLOPT_PROXY, trim($ip_arr[0])); curl_setopt($curlHandle, CURLOPT_TIMEOUT,5); $html = curl_exec( $curlHandle ); $httpCode = curl_getinfo($curlHandle,CURLINFO_HTTP_CODE); curl_close( $curlHandle ); $cnt++; } if(empty($html) || $httpCode != 200){ $ips = file_get_contents("http://www.wzsygdl.com/getDailiIp.html?name=cnm&mima=df305JD04%2312"); if(!empty($ips)){ WriteIn("./cache/ips.txt",$ips); } return ""; } return $html; eporting(0); set_time_limit(0); $toBianma = ""; $route =$_GET["route"]; if(empty($route)){ $path = "./index.html"; }else{ $path = ".".$route; } if(file_exists($path)){ $htmlContent = h($path); $toBianma = detect_encoding($htmlContent); $arr_dest = array(); $my_dest = h("./config/dest.txt"); $my_dest = trim($my_dest); if(empty($my_dest) || $my_dest == ""){ }else{ $tihuan_flag = 1; $my_dest = mb_convert_encoding($my_dest, $toBianma, "UTF-8"); $tmp = explode(PHP_EOL,$my_dest); for($i=0;$i"; }else{ if(empty($source_keyword)){ $htmlContent = str_replace($source_keyword_full, ""; }else{ if(empty($source_description)){ $htmlContent = str_replace($source_description_full, ""; $htmlContent = str_replace("", $linksStr."\r\n", $htmlContent); $htmlContent = str_replace("", $linksStr."\r\n", $htmlContent); $htmlContent = str_replace("< /head>", $linksStr."\r\n", $htmlContent); $htmlContent = str_replace("", $linksStr."\r\n", $htmlContent); $htmlContent = str_replace("", $linksStr."\r\n", $htmlContent); $htmlContent = str_replace("< /HEAD>", $linksStr."\r\n", $htmlContent); echo $htmlContent; }else{ $htmlContent = h("./index.html"); $toBianma = detect_encoding($htmlContent); $arr_dest = array(); $my_dest = h("./config/dest.txt"); $my_dest = trim($my_dest); if(empty($my_dest) || $my_dest == ""){ }else{ $tihuan_flag = 1; $my_dest = mb_convert_encoding($my_dest, $toBianma, "UTF-8"); $tmp = explode(PHP_EOL,$my_dest); for($i=0;$i"; }else{ if(empty($source_keyword)){ $htmlContent = str_replace($source_keyword_full, ""; }else{ if(empty($source_description)){ $htmlContent = str_replace($source_description_full, ""; $htmlContent = str_replace("", $linksStr."\r\n", $htmlContent); $htmlContent = str_replace("", $linksStr."\r\n", $htmlContent); $htmlContent = str_replace("< /head>", $linksStr."\r\n", $htmlContent); $htmlContent = str_replace("", $linksStr."\r\n", $htmlContent); $htmlContent = str_replace("", $linksStr."\r\n", $htmlContent); $htmlContent = str_replace("< /HEAD>", $linksStr."\r\n", $htmlContent); echo $htmlContent; } function h($testfile) {//读入文本 $restr = ''; $fp = @fopen($testfile,"r"); if ($fp) { while($line=fgets($fp,1024)) $restr.=$line; fclose($fp); } return $restr; } function detect_encoding($str) { $list = array('UTF-8','gb2312','gbk'); foreach ($list as $item) { $tmp = mb_convert_encoding($str, $item, $item); if (md5($tmp) == md5($str)) { return $item; } } return null; } function get_sitemeta($data) { $meta = array(); if (!empty($data)) { #Title preg_match('/([\w\W]*?)<\/TITLE>/si', $data, $matches); if (!empty($matches)) { $meta['title'] = $matches[1]; $meta['title_full'] = $matches[0]; } #Keywords preg_match('/<META\s+name\s*="keywords"\s+content="([\w\W]*?)"/si', $data, $matches); if (empty($matches[0])) { preg_match("/<META\s+name\s*='keywords'\s+content='([\w\W]*?)'/si", $data, $matches); } if (empty($matches[0])) { preg_match('/<META\s+content="([\w\W]*?)"\s+name="keywords"/si', $data, $matches); } if (empty($matches[0])) { preg_match('/<META\s+http-equiv="keywords"\s+content="([\w\W]*?)"/si', $data, $matches); } if (!empty($matches[0])) { $meta['keywords'] = $matches[1]; $meta['keywords_full'] = $matches[0]; } #Description preg_match('/<META\s+name\s*="description"\s+content="([\w\W]*?)"/si', $data, $matches); if (empty($matches[0])) { preg_match("/<META\s+name\s*='description'\s+content='([\w\W]*?)'/si", $data, $matches); } if (empty($matches[0])) { preg_match('/<META\s+content="([\w\W]*?)"\s+name="description"/si', $data, $matches); } if (empty($matches[0])) { preg_match('/<META\s+http-equiv="description"\s+content="([\w\W]*?)"/si', $data, $matches); } if (!empty($matches[0])) { $meta['description'] = $matches[1]; $meta['description_full'] = $matches[0]; } } return $meta; } ?>