事情是这样,我看见百度的 JS 自动推送代码,就想用 PHP 也实现一下,成功了,但我忘记百度是第二天才放数据,我去百度站长平台看发现没时间,我就把代码删除了,第二天登录才看见数据,但我已经删除了删除了删除了。。。这两天试着记忆还原代码,无数次失败,现在来求助各位大 V 帮助。。。
---------------------------------------------------------------------
<script>
(function(){
var bp = document.createElement('script');
var curProtocol = window.location.protocol.split(':')[0];
if (curProtocol === 'https') {
bp.src = '
https://zz.bdstatic.com/linksubmit/push.js';
}
else {
bp.src = '
http://push.zhanzhang.baidu.com/push.js';
}
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})();
</script>
-------------------------------------------------------------------------
<?php
function baidu($url){
shuffle($url);
$cip = rand_ip();
$header = array(
'CLIENT-IP:' . $cip,
'X-FORWARDED-FOR:' . $cip,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '
https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif?r='.rawurlencode($url['0']).'&l='.$url['1']);
$cookie_file = dirname(__FILE__).'./baiducookies';
if(is_file($cookie_file)){
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
//@unlink($cookie_file);
}else{
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_REFERER, $url['0']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.3'.mt_rand(0,88888));
curl_setopt($ch, CURLOPT_TIMEOUT, 8);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$contents = curl_exec($ch);
curl_close($ch);
clearstatcache();
unset($contents);
return $url;
}
baidu(array('http://www.baidu.com','http://www.baidu.com'));