discuz x2.0/x2.5论坛加入百度ping功能(php代码)

discuz x2.0/x2.5论坛加入百度ping功能(php代码)

首先创建一个百度ping的代码文件(需要更改URL重定向)

<?php  

// 百度ping的php代码

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>91MKT</string></value></param>

<param><value><string>http://www.91mkt.com/</string></value></param>

<param><value><string>http://www.91mkt.com/</string></value></param>

<param><value><string>http://www.91mkt.com/</string></value></param>

</params>

</methodCall>";

 

$res = postUrl("http://ping.baidu.com/ping/RPC2", $baiduXML);

 

if ( strpos($res, "<int>0</int>") )

{

echo '推送成功';

}

else

{

echo '推送失败';

}

?>

 

如果是Discuz X2,则搜索代码:

showmessage(‘post_newthread_succeed’, “forum.php?mod=viewthread&tid=$tid&extra=$extra”, $param);

替换为:

showmessage(‘post_newthread_succeed’, “ping文件.php”, $param);

 

如果是Discuz X2.5,则搜索代码:

showmessage(‘post_newthread_succeed’, $returnurl, $values, $param);

替换为:

showmessage(‘post_newthread_succeed’, “ping文件.php”, $values, $param);

你可能感兴趣的:(discuz)