黑帽联盟

 找回密码
 会员注册
查看: 2107|回复: 1

[php] php使用百度ping服务代码实例

[复制链接]
yun 黑帽联盟官方人员 

920

主题

37

听众

1364

积分

超级版主

Rank: 8Rank: 8

  • TA的每日心情
    奋斗
    2019-10-18 11:20
  • 签到天数: 678 天

    [LV.9]以坛为家II

    php使用百度ping服务代码实例
    1. <?php

    2. function postUrl($url, $postvar)
    3. {
    4.   $ch = curl_init();
    5.   $headers = array(
    6.     "POST".$url."HTTP/1.0",
    7.     "Content-type: text/xml; charset=\"gb2312\"",
    8.     "Accept: text/xml",
    9.     "Content-length: ".strlen($postvar)
    10.   );
    11.   curl_setopt($ch, CURLOPT_URL, $url);
    12.   curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    13.   curl_setopt($ch, CURLOPT_POST, 1);
    14.   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    15.   curl_setopt($ch, CURLOPT_POSTFIELDS, $postvar);
    16.   $res = curl_exec ($ch);
    17.   curl_close ($ch);
    18.   return $res;
    19. }

    20. $baiduXML = "<?xml version=\"1.0\" encoding=\"gb2312\"?>
    21. <methodCall>
    22.   <methodName>weblogUpdates.extendedPing</methodName>
    23.   <params>
    24.     <param><value><string>黑帽联盟</string></value></param>
    25.     <param><value><string>http://www.cnblackhat.com</string></value></param>
    26.     <param><value><string>https://bbs.cnblackhat.com/thread-961-1-1.html</string></value></param>
    27.     <param><value><string>https://bbs.cnblackhat.com</string></value></param>
    28.   </params>
    29. </methodCall>";

    30. $res = postUrl('http://ping.baidu.com/ping/RPC2', $baiduXML);

    31. if ( strpos($res, "<int>0</int>") )
    32. {
    33.   echo "PING成功";
    34. }else{
    35.   echo "PING失败";
    36. }

    37. ?>
    复制代码
    12.png

    5

    主题

    1

    听众

    104

    积分

    黑帽新手

    Rank: 2

  • TA的每日心情

    2019-3-21 19:51
  • 签到天数: 75 天

    [LV.6]常住居民II

    有没有可能实现发布新文章自动ping百度?
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 会员注册

    发布主题 !fastreply! 收藏帖子 返回列表 搜索
    回顶部