This article mainly introduces the use of Baidu Ping Method example, you can automatically ping the website address Baidu, we refer to the use of it
When using the method access automatically ping to Baidu, my method is to generate the cache, update the cache when the automatic ping Baidu, the return result of 0 indicates success. The code is as follows: $pingarcurl = '/http '. $_server[' http_host '].$_server[' Request_uri ']; $arcping = new Ping (' Home of script ', $pingarcurl, Get_domain (), ' http://www.jb51.net '); $arcping->pingbaidu (); The code is as follows: Class ping{private$title;//blog name private$hosturl;//Blog Home Address private$arturl;//new post 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.= ' params> '; $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 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 (': ' = ' = ' = $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 ', ' RSS address '),//$arc =newping (' title ' of your website, Get_arcurl ($id), Get_domain (), ' http ://www.abc.com/rss.php ');//echo$arc->pingbaidu ();//return result of 0 indicates success.
http://www.bkjia.com/PHPjc/730231.html www.bkjia.com true http://www.bkjia.com/PHPjc/730231.html techarticle This article mainly introduces the use of Baidu Ping Method example, you can put the website address automatically ping to Baidu, we refer to using the method of access to the use of the time automatically ping to Baidu, my method ...