Home > Backend Development > PHP Tutorial > Example of using Baidu ping method Automatically ping Baidu_PHP tutorial

Example of using Baidu ping method Automatically ping Baidu_PHP tutorial

WBOY
Release: 2016-07-13 10:39:46
Original
1071 people have browsed it

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.

Copy code The code is as follows:

$pingarcurl='http://'.$_SERVER['HTTP_HOST '].$_SERVER['REQUEST_URI'];
$arcping = new Ping('Script Home',$pingarcurl,get_domain(),'http://www.jb51.net');
$ arcping->pingbaidu();

Copy code The code is as follows:

class ping{
private$title;//blog name
private $hosturl;//Blog homepage address
private$arturl;//New article address
private$rssurl;//Blog rss address
private$baiduXML;//Baidu XML structure
private$ baiduRPC;//Baidu XML address

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.='weblogUpdates.extendedPing';
$this->baiduXML.='';
$this-> baiduXML.=''.$this->hosturl.'';
$this-> ;baiduXML.=''.$this->title.'';
$this- >baiduXML.=''.$this->arturl.'';
$this ->baiduXML.=''.$this->rssurl.'';
$ 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,"0")) ?true:false;
}
}
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']) ){

$host=$_SERVER['SERVER_ADDR'].$port;

}
}

return$protocol.$host;
}
//$arc=newPing('website title','updated URL address','website domain name','rss address');

//$arc=newPing('title of your website',get_arcurl($id),get_domain(),'http://www.abc.com/rss.php');

//echo$arc- >pingbaidu();
//The return result is 0, indicating success.




http://www.bkjia.com/PHPjc/728118.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/728118.htmlTechArticleAutomatically ping Baidu when accessing using the method. My method is to generate a cache and automatically ping Baidu when updating the cache. , the return result is 0 indicating success. Copy the code The code is as follows: $p...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template