百度ping方法使用樣本_PHP教程

來源:互聯網
上載者:User
這篇文章主要介紹了百度ping方法使用樣本,可以把網站地址自動ping到百度,大家參考使用吧

使用方法訪問的時候自動ping到百度,我的方法是產生緩衝,更新緩衝的時候自動ping百度,返回結果為0表示成功。 代碼如下:$pingarcurl='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];$arcping = new Ping('指令碼之家',$pingarcurl,get_domain(),'http://www.jb51.net');$arcping->pingbaidu(); 代碼如下:class ping{private$title;//部落格名稱private$hosturl;//部落格首頁地址private$arturl;//新發文章地址private$rssurl;//部落格rss地址private$baiduXML;//百度XML結構private$baiduRPC;//百度XML地址 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='http://';/*網域名稱或IP地址*/if(isset($_SERVER['HTTP_X_FORWARDED_HOST'])){$host=$_SERVER['HTTP_X_FORWARDED_HOST'];}elseif(isset($_SERVER['HTTP_HOST'])){$host=$_SERVER['HTTP_HOST'];}else{/*連接埠*/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('網站標題','更新的URL地址','網站網域名稱','rss地址');//$arc=newPing('你網站的title',get_arcurl($id),get_domain(),'http://www.abc.com/rss.php');//echo$arc->pingbaidu();//返回結果為0表示成功。

http://www.bkjia.com/PHPjc/730231.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/730231.htmlTechArticle這篇文章主要介紹了百度ping方法使用樣本,可以把網站地址自動ping到百度,大家參考使用吧 使用方法訪問的時候自動ping到百度,我的方法...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.