当前位置: 移动技术网 > IT编程>开发语言>PHP > php使用百度ping服务代码实例

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

2019年03月23日  | 移动技术网IT编程  | 我要评论

代码实例:

<?php

function posturl($url, $postvar)
{
  $ch = curl_init();
  $headers = array(
    "post".$url."http/1.0",
    "content-type: text/xml; charset=\"gb2312\"",
    "accept: text/xml",
    "content-length: ".strlen($postvar)
  );
  curl_setopt($ch, curlopt_url, $url);
  curl_setopt($ch, curlopt_returntransfer,1);
  curl_setopt($ch, curlopt_post, 1);
  curl_setopt($ch, curlopt_httpheader, $headers);
  curl_setopt($ch, curlopt_postfields, $postvar);
  $res = curl_exec ($ch);
  curl_close ($ch);
  return $res;
}

$baiduxml = "<?xml version=\"1.0\" encoding=\"gb2312\"?>
<methodcall>
  <methodname>weblogupdates.extendedping</methodname>
  <params>
    <param><value><string>愚人渡</string></value></param>
    <param><value><string>//www.jb51.net</string></value></param>
    <param><value><string>//www.jb51.net/read.php?tid-96.html</string></value></param>
    <param><value><string>//www.jb51.net</string></value></param>
  </params>
</methodcall>";

$res = posturl('http://ping.baidu.com/ping/rpc2', $baiduxml);

if ( strpos($res, "<int>0</int>") )
{
  echo "ping成功";
}else{
  echo "ping失败";
}

?>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网