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

分类:PHP_Python| 发布:佚名| 查看: | 发表时间:2014/7/14

代码实例:

<?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>http://www.camnpr.com</string></value></param>
<param><value><string>http://camnpr.com/get.aspx</string></value></param>
<param><value><string>http://www.camnpr.com</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失败";
}
?>

 

365据说看到好文章不转的人,服务器容易宕机
原创文章如转载,请注明:转载自郑州网建-前端开发 http://camnpr.com/
本文链接:http://camnpr.com/php-python/1462.html