浏览 4592 次 / [ 天下网闻 ] 百度瞬间收录DZX论坛方法—搜索引擎PING RPC2服务!DZX2.5/3.0/3.1
  • 发布时间 2014-03-27 06:54
  • 利用百度搜索引擎的PING RPC2服务功能来达到搜索引擎快速收录帖子(推荐)

    实现原理:
    根据百度站长平台的提示(http://zhanzhang.baidu.com/tools/ping),网站程序可以通过PING RPC2服务自动提醒百度搜索引擎收录你的网站,实时收录的哦!

    实现办法:
    1、首先新建一个新文件,文件名自定,放Discuz! X论坛的根目录!要自定名字的原因是,虽然百度提倡这么干,但是你不能老重复的提交啊,老虎屁股动不得!所以改名,以免别人捣蛋,你的站K了啥的,就别赖我了!
    我这里暂定名为: ping_seo.php这里修改网址,将我的站点地址(http://bbs.yeacome.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>http://bbs.yeacome.com/</string></value></param>
    30. <param><value><string>http://bbs.yeacome.com/thread-$canshu-1-1.html</string></value></param>
    31. <param><value><string>http://bbs.yeacome.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:http://bbs.yeacome.com/thread-$canshu-1-1.html");
    38. }
    39. else
    40. {
    41. header ("Location:http://bbs.yeacome.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、修改文件source\include\post\post_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);
    复制代码
    DZX3.1找到:
    1. showmessage($return, $returnurl, array_merge($values, (array)$modthread->param('values')), $modthread->param('param'));
    复制代码
    替换为:
    1. showmessage($return, "ping文件的文件名称.php?action=$tid", array_merge($values, (array)$modthread->param('values')), $modthread->param('param'));
    复制代码
    Tips:
    如果PING失败,那么你发新帖后跳转的网址最后面会有一个#号!
    测试是否PING成功,也可以访问http://你的DZX网址/ping文件的文件名称.php?action=任意新帖子ID,不成功的话,网址后面会有#号。

    记得顺手在这里提交一下你的BBS的RSS!
    http://ping.baidu.com/ping.html
    RSS地址是 http://你的DZX网址/forum.php?mod=rss


    本文选自:
    http://www.discuz.net/thread-2937371-1-1.html

    http://www.discuz.net/forum.php?mod=viewthread&tid=2680576


    谢谢!