PHP的博客ping服務(wù)代碼
更新時間:2012年02月04日 14:06:22 作者:
今天發(fā)一下能夠直接用的ping函數(shù),希望對大家有所幫助,還需要說明的一點(diǎn)是現(xiàn)在的ping并不是像以前那么管用了
PHP的ping服務(wù)代碼其實(shí)在以前我已經(jīng)寫過一個類,不過,有很多朋友加我好友說,看不太懂,那個是以類的形式寫的,可能如果直接放到代碼里直接用不太行,今天發(fā)一下能夠直接用的ping函數(shù),希望對大家有所幫助,還需要說明的一點(diǎn)是現(xiàn)在的ping并不是像以前那么管用了,因?yàn)?,百度和gg可能又加入了其它的指標(biāo),新網(wǎng)站ping能成功,但不一定是百分百收錄。
<?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>WEB開發(fā)筆記</string></value></param>
<param><value><string>http://www.dbjr.com.cn</string></value></param>
<param><value><string>http://www.dbjr.com.cn/001</string></value></param>
<param><value><string>http://www.dbjr.com.cn</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失敗";
}
?>
復(fù)制代碼 代碼如下:
<?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>WEB開發(fā)筆記</string></value></param>
<param><value><string>http://www.dbjr.com.cn</string></value></param>
<param><value><string>http://www.dbjr.com.cn/001</string></value></param>
<param><value><string>http://www.dbjr.com.cn</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失敗";
}
?>
相關(guān)文章
PHP實(shí)現(xiàn)簡單注冊登錄系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了PHP實(shí)現(xiàn)簡單注冊登錄系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-12-12php獲取遠(yuǎn)程圖片的兩種 CURL方式和sockets方式獲取遠(yuǎn)程圖片
php獲取遠(yuǎn)程圖片的兩種:CURL方式和sockets方式獲取遠(yuǎn)程圖片,需要的朋友可以參考下。2011-11-11PHP在終端中實(shí)現(xiàn)進(jìn)度條來處理數(shù)據(jù)的示例詳解
在PHP中,有時候你需要在終端中處理大量數(shù)據(jù)或執(zhí)行長時間運(yùn)行的任務(wù),同時希望能夠?qū)崟r跟蹤任務(wù)的進(jìn)度,在 PHP 中,有時候你需要在終端中處理大量數(shù)據(jù)或執(zhí)行長時間運(yùn)行的任務(wù),同時希望能夠?qū)崟r跟蹤任務(wù)的進(jìn)度,需要的朋友可以參考下2023-10-10