用php实现Google /Baidu Ping服务快速收录
生活随笔
收集整理的這篇文章主要介紹了
用php实现Google /Baidu Ping服务快速收录
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
玩過(guò)WORDPRESS的朋友應(yīng)該都知道ping服務(wù)吧,通俗點(diǎn)講它可以在更新文章的時(shí)候向Google、baidu及其他支持ping的搜索引擎發(fā)送指令然后招呼它們過(guò)來(lái),不用傻等他們過(guò)來(lái)收錄了,化被動(dòng)為主動(dòng)了。直接貼代碼了,很簡(jiǎn)單的。
谷歌說(shuō)明文檔:https://www.google.com/intl/zh-CN/help/blogsearch/pinging_API.html
baidu 說(shuō)明文檔:http://help.baidu.com/question?prod_en=master&class=478&id=3046
/**+------------------------------------------------------------------------------* 通知搜索引擎過(guò)來(lái)抓去最新發(fā)布的內(nèi)容。秒收不是夢(mèng)* 目前僅支持Google和Baidu+------------------------------------------------------------------------------*/ class ping {public $method, $callback;public function method($site_name, $site_url, $update_url, $update_rss) {$this->method = "<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>weblogUpdates.extendedPing</methodName><params><param><value>{$site_name}</value></param><param><value>{$site_url}</value></param><param><value>{$update_url}</value></param><param><value>{$update_rss}</value></param></params></methodCall>";return $this->method;}public function _post($url, $postvar) {$ch = curl_init();$headers = array("POST " . $url . " HTTP/1.0","Content-type: text/xml;charset="utf-8"","Accept: text/xml","Content-length: " . strlen($postvar));curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);curl_setopt($ch, CURLOPT_POSTFIELDS, $postvar);$res = curl_exec($ch);curl_close($ch);return $res;}public function google() {$this->callback = $this->_post('http://blogsearch.google.com/ping/RPC2', $this->method);return strpos($this->callback, "<boolean>0</boolean>") ? true : false;}public function baidu() {$this->callback = $this->_post('http://ping.baidu.com/ping/RPC2', $this->method);return strpos($this->callback, "<int>0</int>") ? true : false;}}轉(zhuǎn)載于:https://my.oschina.net/afengzxf/blog/1634413
總結(jié)
以上是生活随笔為你收集整理的用php实现Google /Baidu Ping服务快速收录的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 发布你的程序包到Nuget
- 下一篇: 一个超赞又好用的PHP技巧!如何生成PH