个人学习、工作的经验整理!

织梦dedebiz百度手动推送PHP代码

网站建设 来源:未知 作者:admin

织梦dedebiz百度手动推送PHP代码

手动推送到百度,可以缩短百度爬虫发现你网站新链接的时间,让新发布的页面第一时间被百度收录。

也能更换保护原创,对于网站最新的原创内容,可以利用主动推送功能快速通知百度,让内容得以转发之前被百度发现。

织梦dedebiz百度php主动推送代码简单步骤:

1.先在根目录建立文件为tuisong.php,把代码放进去根据自己的配置好文件



<?php
require_once ("system/common.inc.php");
require_once "system/archive/partview.class.php";
require_once('system/charset.func.php');
$year = date("Y");
$month = date("m");
$day = date("d");
$dayBegin = mktime(0,0,0,$month,$day,$year);
$dayEnd = mktime(23,59,59,$month,$day,$year);
$query = "SELECT arch.id,types.typedir FROM biz_arctype as types inner join biz_archives as arch on types.id=arch.typeid where pubdate<".$dayEnd." AND pubdate>".$dayBegin." limit 3000";//biz_arctype数据表不是biz请更换,3000是推送数量
$urls="";
$dsql->Execute('arch.id,types.typedir',$query);
while($row = $dsql->GetArray('arch.id,types.typedir'))
{
	//$urls.="http://www.xxx.com".$row[id].".html".",";//伪静态网页版
    $urls.="http://www.xxx.com".str_replace("{cmspath}","",$row['typedir'])."/".$row[id].".html".",";//静态网页版
}
$urls = substr($urls,0,-1);
$urls = explode(",",$urls);
$api = 'http://data.zz.baidu.com/urls?site=';//更换百度百度推送接口密钥,在百度搜索资源平台获取
$ch = curl_init();
$options =  array(
    CURLOPT_URL => $api,
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => implode("
", $urls),
    CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
echo $result;
?>

2.运行http://xxx.com/tuisong.php

{"remain":2996,"success":4}

这是完成百度推送的反馈,成功推送4条,今天还可以推送2996条。


答案有错 or 我有答案