百度主动推送的代码,不需要每天手动去添加地址推送,只要浏览器打开推送请求,不要关掉浏览器,程序自动帮你推送。(该插件只推送内容页,支持动态、伪静态、静态页面的推送,但这三种地址规则需要去代码里面自行拼接)下面来说下,用这个插件注意事项:1、首先要在数据库表名_data表里面加一个字段,字段名为v_push , 字段类型为 int(说俗点就是整数类型,我怕有人看不懂),字段默认值设置为02、下面是一些代码上的注意事项,下面的代码只是部分需要注意的代码 <?phprequire_once("include/common.php");require_once("include/main.class.php");require_once("data/config.cache.inc.php");//设置每次推送的条数$tnum = 30;$remain = $_REQUEST['remain'];$remain = isset($remain) ? intval($remain) : $tnum;/*百度推送系统更新,不再限制推送条数,但remain参数保留,始终为1,为了防止官方把remain参数再次用上,这边也把remain保留,但不影响推送功能 百度推送好像限制了不能重复推送,否则将禁止该网站推送功能,现在只能每个地址推送一次。如果有的网友想重复推送,请往下看。if($remain>30) $pagesize=30;else $pagesize=$remain;*/$pagesize=$tnum;$wheresql = "where v_push = 0 ";$trow = $dsql->GetOne("Select count(*) as dd From `sea_data` $wheresql");$totalnum = $trow['dd'];//当总页数小于每页数目的时候,替换pagesizeif($totalnum<$pagesize) $pagesize = $totalnum;if(empty($totalpage)) $totalpage=ceil($totalnum/$pagesize);if($totalnum==0 || $page>$totalpage || $remain==0){ /*---------------------------如果依然想重复推送的朋友,你可以把下面三行代码给注释掉。------------------------------*/ echo "恭喜,已推送所有内容页!"; echo "<br>暂停3秒后继续推送<script language="javascript">setTimeout("baiduPush();",3000);function baiduPush(){location.href='?remain=1';}</script></div>"; return; /*---------------------------如果依然想重复推送的朋友,你可以把上面三行代码给注释掉。------------------------------*/ /*---------------------------如果依然想重复推送的朋友,你可以把下面三行代码注释给取消掉。-------------------------*/ //$query = "Update `sea_data` set v_push=0"; //$dsql->ExecuteNoneQuery($query); //$pagesize = $tnum; /*---------------------------如果依然想重复推送的朋友,你可以把上面三行代码注释给取消掉。-------------------------*/ }$dsql->SetQuery("Select v_id From `sea_data` $wheresql order by v_id desc limit 0,$pagesize");$dsql->Execute('video_list');$plink ="";$urls = array();$ids = array();$result ="{}";while($row=$dsql->GetObject('video_list')){ $v_id = $row->v_id; /*-----------------------------------------------------------------------------------------------------------*/ /*通过v_id来拼接内容页的地址,动态、伪静态、静态的内容页地址规律都不一样,请大家自行修改。$cfg_basehost代表你的域名*/ /*!!!!!!!!注意这里暂不支持已电影拼音做内容页地址的链接推送!!!!!!!!!!*/ /*-----------------------------------------------------------------------------------------------------------*/ $plink = $cfg_basehost."/detail/index".$v_id.".html"; //来源页面网址 array_push($urls ,$plink); array_push($ids ,$v_id); @ob_flush(); @flush();}//百度推送API地址,请各自去百度站长平台查看自己的token$api = 'http://data.zz.baidu.com/urls?site=www.xxx.com&token=es8rdbhGjGjhUJBfNI';$ch = curl_init();$options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode("n", $urls), CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), );curl_setopt_array($ch, $options);$result = curl_exec($ch);$result_json = json_decode($result, true); if(isset($result_json["remain"])){ //对ids数组循环,提示推送成功id,更新对应id的v_push=1 foreach ($ids as $vid){ $query = "Update `sea_data` set v_push=1 where v_id='$vid'"; $dsql->ExecuteNoneQuery($query); echo $result ."已成功推送URL:".$cfg_basehost."/detail/index".$vid.".html"; echo '<br />'; } $remaincount = $result_json["remain"]; echo "<br>暂停3秒后继续推送<script language="javascript">setTimeout("baiduPush();",3000);function baiduPush(){location.href='?remain=".$remaincount."';}</script></div>";}else{ echo "今天百度推送次数已达上限!请明天再推送!"; echo "<br>暂停3秒后继续推送<script language="javascript">setTimeout("baiduPush();",3000);function baiduPush(){location.href='?remain=1';}</script></div>"; exit();}?>
|