Baidu ping method example _ PHP Tutorial

Source: Internet
Author: User
Baidu ping method example. This article mainly introduces the use example of Baidu ping method. you can automatically ping the website address to Baidu. for details, refer to how to use this method to automatically ping Baidu, my method this article mainly introduces the Baidu ping method example. you can automatically ping the website address to Baidu. For more information, see.

When using this method to access Baidu, I can use this method to generate a cache. when updating the cache, I can automatically ping Baidu. if the returned result is 0, the request is successful. The code is as follows: $ pingarcurl = 'http ://'. $ _ SERVER ['http _ host']. $ _ SERVER ['request _ URI ']; $ arcping = new Ping ('foothome', $ pingarcurl, get_domain (), 'http: // www.jb51.net '); $ arcping-> pingbaidu (); code: 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 {$ po Rt = '';} 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 ('your website title', get_arcurl ($ id), get_domain (), 'http: // www.abc.com/rss.php '); // echo $ arc-> pingbaidu (); // if the returned result is 0, the request is successful.

Baidu is automatically pinged to Baidu when using method access. my method...

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.