Home > Backend Development > PHP Tutorial > Baidu ping method usage example_PHP tutorial

Baidu ping method usage example_PHP tutorial

WBOY
Release: 2016-07-13 10:39:22
Original
976 people have browsed it

This article mainly introduces the example of using Baidu ping method, which can automatically ping the website address to Baidu. Please use it for reference

Automatically 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. ​ ​ 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(); ​ 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); 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,"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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/730231.htmlTechArticleThis article mainly introduces the example of Baidu ping method, which can automatically ping the website address to Baidu. Please refer to it for reference. Use the method to automatically ping Baidu when accessing. My method...
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