discuz教程:PING快速實(shí)現(xiàn)百度秒收錄
一、利用百度搜索引擎的PING RPC2服務(wù)功能來(lái)達(dá)到搜索引擎快速收錄帖子(推薦)
實(shí)現(xiàn)原理:
根據(jù)百度站長(zhǎng)平臺(tái)的提示,網(wǎng)站程序可以通過(guò)PING RPC2服務(wù)自動(dòng)提醒百度搜索引擎收錄你的網(wǎng)站,實(shí)時(shí)收錄的哦!
實(shí)現(xiàn)辦法:
1、首先新建一個(gè)新文件,文件名自定,放Discuz! X論壇的根目錄!要自定名字的原因是,雖然百度提倡這么干,但是你不能老重復(fù)的提交啊,老虎屁股動(dòng)不得!所以改名,以免別人搗蛋,你的站K了啥的,就別賴我了!
我這里暫定名為: ping_seo.php這里修改網(wǎng)址,將我的站點(diǎn)地址(http://bbs.yeacome.com)改為你的。
開啟了偽靜態(tài)的ping.php代碼用這個(gè):
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 = "
";
$res = postUrl('http://ping.baidu.com/ping/RPC2', $baiduXML);
if ( strpos($res, "0 ") )
{
header ("Location:http://bbs.yeacome.com/thread-$canshu-1-1.html");
}
else
{
header ("Location:http://bbs.yeacome.com/thread-$canshu-1-1.html#");
}
?>
復(fù)制代碼
未啟了偽靜態(tài)的ping.php代碼用這個(gè):
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 = "
";
$res = postUrl('http://ping.baidu.com/ping/RPC2', $baiduXML);
if ( strpos($res, "0 ") )
{
header ("Location:http://你的DZX網(wǎng)址/forum.php?mod=viewthread&tid=$canshu");
}
else
{
header ("Location:http://你的DZX網(wǎng)址/forum.php?mod=viewthread&tid=$canshu#");
}
?>
復(fù)制代碼
2、修改文件sourceincludepostpost_newthread.php,
Discuz X2.0找到
showmessage('post_newthread_succeed', "forum.php?mod=viewthread&tid=$tid&extra=$extra", $param);
復(fù)制代碼
替換為(其中ping_seo為你自己的自定義ping文件名稱):
showmessage('post_newthread_succeed', "ping_seo.php?action=$tid", $param);
復(fù)制代碼
DZX2.5找到:
showmessage('post_newthread_succeed', $returnurl, $values, $param);
復(fù)制代碼
替換為(其中ping_seo為你自己的自定義ping文件名稱):
showmessage('post_newthread_succeed', "ping文件的文件名稱.php?action=$tid", $values, $param);
復(fù)制代碼
OK,簡(jiǎn)單兩步完成,需要花冤枉錢么?
Tips:
如果PING失敗,那么你發(fā)新帖后跳轉(zhuǎn)的網(wǎng)址最后面會(huì)有一個(gè)#號(hào)!
測(cè)試是否PING成功,也可以訪問(wèn)http://你的DZX網(wǎng)址/ping文件的文件名稱.php?action=任意新帖子ID,不成功的話,網(wǎng)址后面會(huì)有#號(hào)。
今天的教程就到這里,大家有什么疑問(wèn)歡迎來(lái)提問(wèn)。
版權(quán)聲明:
本站所有文章和圖片均來(lái)自用戶分享和網(wǎng)絡(luò)收集,文章和圖片版權(quán)歸原作者及原出處所有,僅供學(xué)習(xí)與參考,請(qǐng)勿用于商業(yè)用途,如果損害了您的權(quán)利,請(qǐng)聯(lián)系網(wǎng)站客服處理。