php使用百度ping服务代码实例
程序员文章站
2022-07-20 22:58:10
代码实例:
代码实例:
<?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失败"; } ?>