一、利用百度搜尋引擎的 PING RPC2 服務功能來達到搜尋引擎快速收錄帖子 (推薦)
實現原理:
根據百度站長平臺的提示,網站程式可以透過 PING RPC2 服務自動提醒百度搜尋引擎收錄你的網站,即時收錄的哦!

實現辦法:
1 、首先新建一個新檔案,檔名自定,放 Discuz! X 論壇的根目錄!要自定名字的原因是,雖然百度提倡這麼幹,但是你不能老重複的提交啊,老虎屁股動不得!所以改名,以免別人搗蛋,你的站 K 了啥的,就別賴我了!
我這裡暫定名為: ping_seo.php 這裡修改網址,將我的站點地址 (http://bbs.weixiaoduo.com) 改為你的。
開啟了偽靜態的 ping.php 程式碼用這個:

  1. <?php
  2. if(isset($_GET['action']))
  3. {
  4. $canshu=$_GET['action'];
  5. }
  6. function postUrl($url, $postvar)
  7. {
  8. $ch = curl_init();
  9. $headers = array(
  10. "POST ".$url." HTTP/1.0",
  11. "Content-type: text/xml; charset="utf-8"",
  12. "Accept: text/xml",
  13. "Content-length: ".strlen($postvar)
  14. );
  15. curl_setopt($ch, CURLOPT_URL, $url);
  16. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  17. curl_setopt($ch, CURLOPT_POST, 1);
  18. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  19. curl_setopt($ch, CURLOPT_POSTFIELDS, $postvar);
  20. $res = curl_exec ($ch);
  21. curl_close ($ch);
  22. return $res;
  23. }
  24. $baiduXML = "<?xml version="1.0" encoding="utf-8"?>
  25. <methodCall>
  26. <methodName>weblogUpdates.extendedPing</methodName>
  27. <params>
  28. <param><value><string> 薇曉朵技術論壇</string></value></param>
  29. <param><value><string>https://bbs.weixiaoduo.com/</string></value></param>
  30. <param><value><string>https://bbs.weixiaoduo.com/thread-$canshu-1-1.html</string></value></param>
  31. <param><value><string>https://bbs.weixiaoduo.com/forum.php?mod=rss</string></value></param>
  32. </params>
  33. </methodCall>";
  34. $res = postUrl('http://ping.baidu.com/ping/RPC2', $baiduXML);
  35. if ( strpos($res, "<int>0</int>") )
  36. {
  37. header ("Location:https://bbs.weixiaoduo.com/thread-$canshu-1-1.html");
  38. }
  39. else
  40. {
  41. header ("Location:https://bbs.weixiaoduo.com/thread-$canshu-1-1.html#");
  42. }
  43. ?>

未啟了偽靜態的 ping.php 程式碼用這個:

  1. <?php
  2. if(isset($_GET['action']))
  3. {
  4. $canshu=$_GET['action'];
  5. }
  6. function postUrl($url, $postvar)
  7. {
  8. $ch = curl_init();
  9. $headers = array(
  10. "POST ".$url." HTTP/1.0",
  11. "Content-type: text/xml; charset="utf-8"",
  12. "Accept: text/xml",
  13. "Content-length: ".strlen($postvar)
  14. );
  15. curl_setopt($ch, CURLOPT_URL, $url);
  16. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  17. curl_setopt($ch, CURLOPT_POST, 1);
  18. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  19. curl_setopt($ch, CURLOPT_POSTFIELDS, $postvar);
  20. $res = curl_exec ($ch);
  21. curl_close ($ch);
  22. return $res;
  23. }
  24. $baiduXML = "<?xml version="1.0" encoding="utf-8"?>
  25. <methodCall>
  26. <methodName>weblogUpdates.extendedPing</methodName>
  27. <params>
  28. <param><value><string> 你的站名</string></value></param>
  29. <param><value><string>http://你的 DZX 網址/</string></value></param>
  30. <param><value><string>http://你的 DZX 網址
    /forum.php?mod=viewthread&tid=$canshu</string></value></param>
  31. <param><value><string>http://你的 DZX 網址/forum.php?mod=rss</string></value></param>
  32. </params>
  33. </methodCall>";
  34. $res = postUrl('http://ping.baidu.com/ping/RPC2', $baiduXML);
  35. if ( strpos($res, "<int>0</int>") )
  36. {
  37. header ("Location:http://你的 DZX 網址/forum.php?mod=viewthread&tid=$canshu");
  38. }
  39. else
  40. {
  41. header ("Location:http://你的 DZX 網址/forum.php?mod=viewthread&tid=$canshu#");
  42. }
  43. ?>

2 、修改檔案 sourceincludepostpost_newthread.php,
Discuz X2.0 找到

  1. showmessage('post_newthread_succeed', "forum.php?mod=viewthread&tid=$tid&extra=$extra", $param);

替換為 (其中 ping_seo 為你自己的自定義 ping 檔名稱):

  1. showmessage('post_newthread_succeed', "ping_seo.php?action=$tid", $param);

DZX2.5 找到:

  1. showmessage('post_newthread_succeed', $returnurl, $values, $param);

替換為 (其中 ping_seo 為你自己的自定義 ping 檔名稱):

  1. showmessage('post_newthread_succeed', "ping 檔案的檔名稱.php?action=$tid", $values, $param);

OK,簡單兩步完成,需要花冤枉錢麼?

Tips:
如果 PING 失敗,那麼你發新帖後跳轉的網址最後面會有一個 #號!
測試是否 PING 成功,也可以訪問 http://你的 DZX 網址/ping 檔案的檔名稱.php?action=任意新帖子 ID,不成功的話,網址後面會有 #號。
今天的教程就到這裡,大家有什麼疑問歡迎來提問。