当前位置:Gxlcms > php框架 > php使用百度ping服务代码实例

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

时间:2021-07-01 10:21:17 帮助过:45人阅读

代码实例:

  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>//www.gxlcms.com</string></value></param>
  26. <param><value><string>//www.gxlcms.com/read.php?tid-96.html</string></value></param>
  27. <param><value><string>//www.gxlcms.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. ?>

人气教程排行