|
使用方法訪問的時(shí)候自動ping到百度,我的方法是生成緩存,更新緩存的時(shí)候自動ping百度,返回結(jié)果為0表示成功。
復(fù)制代碼 代碼如下:
$pingarcurl='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$arcping = new Ping('腳本之家',$pingarcurl,get_domain(),'http://www.jb51.NET');
$arcping->pingbaidu();
復(fù)制代碼 代碼如下:
class ping{
private$title;//博客名稱
private$hosturl;//博客首頁地址
private$arturl;//新發(fā)文章地址
private$rssurl;//博客rss地址
private$baiduXML;//百度XML結(jié)構(gòu)
private$baiduRPC;//百度XML地址
publicfunction__construct($title,$arturl,$hosturl,$rssurl)
{
if(empty($title)||empty($arturl))
returnfalse;
$this->title=$title;
$this->hosturl=$hosturl;
$this->rssurl=$rssurl;
$this->arturl=$arturl;
$this->baiduRPC='http://ping.baidu.com/ping/RPC2';
$this->baiduXML='<?xmlversion=/"1.0/"encoding=/"UTF-8/"?>';
$this->baiduXML.='<methodCall>';
$this->baiduXML.='<methodName>weblogUpdates.extendedPing</methodName>';
$this->baiduXML.='<params>';
$this->baiduXML.='<param><value><string>'.$this->hosturl.'</string></value></param>';
$this->baiduXML.='<param><value><string>'.$this->title.'</string></value></param>';
$this->baiduXML.='<param><value><string>'.$this->arturl.'</string></value></param>';
$this->baiduXML.='<param><value><string>'.$this->rssurl.'</string></value></param>';
$this->baiduXML.='</params>';
$this->baiduXML.='</methodCall>';
}
publicfunctionpingbaidu()
{
$ch=curl_init();
$headers=array(
'User-Agent:request',
'Host:ping.baidu.com',
'Content-Type:text/xml',
);
curl_setopt($ch,CURLOPT_URL,$this->baiduRPC);
curl_setopt($ch,CURLOPT_HEADER,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_POSTFIELDS,$this->baiduXML);
$res=curl_exec($ch);
curl_close($ch);
//return$res;
return(strpos($res,"<int>0</int>"))?true:false;
}
}
functionget_domain()
{
/*協(xié)議*/
$protocol='http://';
/*域名或IP地址*/
if(isset($_SERVER['HTTP_X_FORWARDED_HOST'])){
$host=$_SERVER['HTTP_X_FORWARDED_HOST'];
}elseif(isset($_SERVER['HTTP_HOST'])){
$host=$_SERVER['HTTP_HOST'];
}else{
/*端口*/
if(isset($_SERVER['SERVER_PORT'])){
$port=':'.$_SERVER['SERVER_PORT'];
if((':80'==$port&'http://'==$protocol)||(':443'==$port&'https://'==$protocol)){
$port='';
}
}else{
$port='';
}
if(isset($_SERVER['SERVER_NAME'])){
$host=$_SERVER['SERVER_NAME'].$port;
}elseif(isset($_SERVER['SERVER_ADDR'])){
$host=$_SERVER['SERVER_ADDR'].$port;
}
}
return$protocol.$host;
}
//$arc=newPing('網(wǎng)站標(biāo)題','更新的URL地址','網(wǎng)站域名','rss地址');
//$arc=newPing('你網(wǎng)站的title',get_arcurl($id),get_domain(),'http://www.abc.com/rss.php');
//echo$arc->pingbaidu();
//返回結(jié)果為0表示成功。
php技術(shù):百度ping方法使用示例 自動ping百度,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。