Automatically ping Baidu when accessing using this method. My method is to generate a cache and automatically ping Baidu when updating the cache. The return result is 0, which means success.
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='';
$this->baiduXML.='
$this->baiduXML.='
$this->baiduXML.='
$this-> baiduXML.='
$this-> ;baiduXML.='
$this- >baiduXML.='
$this ->baiduXML.='
$ this->baiduXML.='
$this->baiduXML.='
}
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 ; $res=curl_exec($ch);
curl_close($ch);
//return$res;
return(strpos($res,"
}
}
functionget_domain()
{
/*Protocol*/
$protocol='http://';
/*Domain name Or IP address */
if(isset($_SERVER['HTTP_X_FORWARDED_HOST'])){
$host=$_SERVER['HTTP_X_FORWARDED_HOST'];
}elseif(isset($_SERVER['HTTP_HOST' ])){
$host=$_SERVER['HTTP_HOST'];
}else{
/*Port*/
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']) ){
}
}
return$protocol.$host;
}
//$arc=newPing('website title','updated URL address','website domain name','rss address');
//echo$arc- >pingbaidu();
//The return result is 0, indicating success.
www.bkjia.com