一、利用百度搜索引擎的 PING RPC2 服務功能來達到搜索引擎快速收錄帖子 (推薦)
實現原理:
根據百度站長平台的提示,網站程序可以通過 PING RPC2 服務自動提醒百度搜索引擎收錄你的網站,即時收錄的哦!
實現辦法:
1 、首先新建一個新文件,文件名自定,放 Discuz! X 論壇的根目錄!要自定名字的原因是,雖然百度提倡這麼幹,但是你不能老重複的提交啊,老虎屁股動不得!所以改名,以免別人搗蛋,你的站 K 了啥的,就別賴我了!
我這裏暫定名為: ping_seo.php 這裏修改網址,將我的站點地址 (http://bbs.weixiaoduo.com) 改為你的。
開啓了偽靜態的 ping.php 代碼用這個:
- <?php
- if(isset($_GET['action']))
- {
- $canshu=$_GET['action'];
- }
- function postUrl($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;
- }
- $baiduXML = "<?xml version="1.0" encoding="utf-8"?>
- <methodCall>
- <methodName>weblogUpdates.extendedPing</methodName>
- <params>
- <param><value><string> 薇曉朵技術論壇</string></value></param>
- <param><value><string>https://bbs.weixiaoduo.com/</string></value></param>
- <param><value><string>https://bbs.weixiaoduo.com/thread-$canshu-1-1.html</string></value></param>
- <param><value><string>https://bbs.weixiaoduo.com/forum.php?mod=rss</string></value></param>
- </params>
- </methodCall>";
- $res = postUrl('http://ping.baidu.com/ping/RPC2', $baiduXML);
- if ( strpos($res, "<int>0</int>") )
- {
- header ("Location:https://bbs.weixiaoduo.com/thread-$canshu-1-1.html");
- }
- else
- {
- header ("Location:https://bbs.weixiaoduo.com/thread-$canshu-1-1.html#");
- }
- ?>
未啓了偽靜態的 ping.php 代碼用這個:
- <?php
- if(isset($_GET['action']))
- {
- $canshu=$_GET['action'];
- }
- function postUrl($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;
- }
- $baiduXML = "<?xml version="1.0" encoding="utf-8"?>
- <methodCall>
- <methodName>weblogUpdates.extendedPing</methodName>
- <params>
- <param><value><string> 你的站名</string></value></param>
- <param><value><string>http://你的 DZX 網址/</string></value></param>
- <param><value><string>http://你的 DZX 網址
/forum.php?mod=viewthread&tid=$canshu</string></value></param> - <param><value><string>http://你的 DZX 網址/forum.php?mod=rss</string></value></param>
- </params>
- </methodCall>";
- $res = postUrl('http://ping.baidu.com/ping/RPC2', $baiduXML);
- if ( strpos($res, "<int>0</int>") )
- {
- header ("Location:http://你的 DZX 網址/forum.php?mod=viewthread&tid=$canshu");
- }
- else
- {
- header ("Location:http://你的 DZX 網址/forum.php?mod=viewthread&tid=$canshu#");
- }
- ?>
2 、修改文件 sourceincludepostpost_newthread.php,
Discuz X2.0 找到
- showmessage('post_newthread_succeed', "forum.php?mod=viewthread&tid=$tid&extra=$extra", $param);
替換為 (其中 ping_seo 為你自己的自定義 ping 文件名稱):
- showmessage('post_newthread_succeed', "ping_seo.php?action=$tid", $param);
DZX2.5 找到:
- showmessage('post_newthread_succeed', $returnurl, $values, $param);
替換為 (其中 ping_seo 為你自己的自定義 ping 文件名稱):
- showmessage('post_newthread_succeed', "ping 文件的文件名稱.php?action=$tid", $values, $param);
OK,簡單兩步完成,需要花冤枉錢麼?
Tips:
如果 PING 失敗,那麼你發新帖後跳轉的網址最後面會有一個 #號!
測試是否 PING 成功,也可以訪問 http://你的 DZX 網址/ping 文件的文件名稱.php?action=任意新帖子 ID,不成功的話,網址後面會有 #號。
今天的教程就到這裏,大家有什麼疑問歡迎來提問。