Baidu Ping Method Use example

Source: Internet
Author: User

  This article mainly introduces the use of Baidu Ping Method example, you can automatically ping the website address to Baidu, we refer to the use of the bar

When using the method access automatically ping to Baidu, my method is to generate the cache, update the cache when automatically ping Baidu, return the result of 0 to indicate success.     Code as follows: $pingarcurl = ' http://' $_server[' http_host '].$_server[' Request_uri ']; $arcping = new Ping (' Script House ', $pingarcurl, Get_domain (), ' http://www.jb51.net '); $arcping->pingbaidu ();   Code 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= ' <?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 () {/* 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 (': = = = $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 (' site title ', ' Updated URL ', ' site domain name ', ' RSS address '); $arc =newping (' title of your site ', Get_arcurl ($id), Get_domain (), ' http://www.abc.com/rss.php '); Echo$arc->pingbaidu (); The return result of 0 indicates success.  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.