用 PHP 写了一个百度提交,结果我就懵了

2017-04-05 19:10:02 +08:00
 VgV
事情是这样,我看见百度的 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'));
2135 次点击
所在节点    PHP
4 条回复
ye10010
2017-04-06 00:03:54 +08:00
话说为什么又要用 php 实现?
用 php 实现主动推送就好了,百度有接口.
和 js 的自动推送配合使用.
VgV
2017-04-06 00:13:35 +08:00
@ye10010 为了方便,我想把 JS 自动推送修改成和主动推送一起用,这样 JS 每次推送就不用打开每个页面了,但 JS 好像有超时还是什么,我现在想不起来当初是怎么成功的,按照记忆还原代码试了几天还是失败。
andyhuzhill
2017-04-06 08:59:15 +08:00
所以说 版本控制系统 是很有用的啊
我一般写什么小的测试代码 都会用 git 保存一下
zhaixiaohu
2017-04-06 10:25:20 +08:00
百度论坛有现成的工具啊,直接去论坛下载就行了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/352736

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX