V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
VgV
V2EX  ›  PHP

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

  •  
  •   VgV · 2017-04-05 19:10:02 +08:00 · 2125 次点击
    这是一个创建于 2581 天前的主题,其中的信息可能已经有所发展或是发生改变。
    事情是这样,我看见百度的 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'));
    ye10010
        1
    ye10010  
       2017-04-06 00:03:54 +08:00
    话说为什么又要用 php 实现?
    用 php 实现主动推送就好了,百度有接口.
    和 js 的自动推送配合使用.
    VgV
        2
    VgV  
    OP
       2017-04-06 00:13:35 +08:00
    @ye10010 为了方便,我想把 JS 自动推送修改成和主动推送一起用,这样 JS 每次推送就不用打开每个页面了,但 JS 好像有超时还是什么,我现在想不起来当初是怎么成功的,按照记忆还原代码试了几天还是失败。
    andyhuzhill
        3
    andyhuzhill  
       2017-04-06 08:59:15 +08:00
    所以说 版本控制系统 是很有用的啊
    我一般写什么小的测试代码 都会用 git 保存一下
    zhaixiaohu
        4
    zhaixiaohu  
       2017-04-06 10:25:20 +08:00
    百度论坛有现成的工具啊,直接去论坛下载就行了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1399 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 17:15 · PVG 01:15 · LAX 10:15 · JFK 13:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.