<bdo id="ylihq"></bdo>
<track id="ylihq"><div id="ylihq"></div></track>
    <track id="ylihq"><span id="ylihq"></span></track>

    <track id="ylihq"><div id="ylihq"></div></track>
    <track id="ylihq"></track>

    百度站長實時網址批量主動推送 PHP教程

    2020-06-03 21:18 原創
    閱讀數:8

    一、修改說明:便于站長使用。 二、教程講解: 新建文件 baidu_push.php ...

    一、修改說明:便于站長使用。
    二、教程講解:
    1、新建文件 baidu_push.php
    $beginToday = date(strtotime(date("Y-m-d",time())));//今天 開始時間 ?
    $beginThisweek = date(strtotime('-1 monday', time()));//本周 開始時間 ?
    $beginLastweek = date(strtotime('-2 monday', time()));//上周 開始時間
    $beginThismonth = date(strtotime(date('Y-m', time())));//本月 開始時間
    $beginThismonths = date(strtotime('-1 day',$beginThismonth));//上月最后一天 開始時間
    $baidu_push_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];//獲取URL
    //存在記錄(每天提交數量有限,解決多次提交的問題)
    if($baidu_push = DB::fetch_first("SELECT * FROM ".DB::table('baidu_push')." WHERE url = '$baidu_push_url'")){
    	$sid = $baidu_push['sid'];//ID
    	$gxs = $baidu_push['gxs']+1;//更新次數
    	$tjs = $baidu_push['tjs']+1;//提交次數
    	$sta = $baidu_push['status'];//狀態
    	if($sta == '1'){//狀態等于1 一周提交一次
    		if($beginThisweek > $baidu_push['dateline']){
    			$urls_push = array(
    				$baidu_push_url,
    			);
    			$api_push = 'http://data.zz.baidu.com/urls?site='.$_SERVER['HTTP_HOST'].'&token=這里是16位字母和數字組合的字符串';
    			$ch_push = curl_init();
    			$options_push =  array(
    				CURLOPT_URL => $api_push,
    				CURLOPT_POST => true,
    				CURLOPT_RETURNTRANSFER => true,
    				CURLOPT_POSTFIELDS => implode("\n", $urls_push),
    				CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
    			);
    			curl_setopt_array($ch_push, $options_push);
    			$result_push = curl_exec($ch_push);
    			DB::update('baidu_push', ['updatetime' => time(), 'gxs' => $gxs, 'tjs' => $tjs], 'sid = '.$sid);
    		}
    	}else{//狀態等于0 第二天提交
    		if($beginToday > $baidu_push['dateline']){
    			$urls_push = array(
    				$baidu_push_url,
    			);
    			$api_push = 'http://data.zz.baidu.com/urls?site='.$_SERVER['HTTP_HOST'].'&token=這里是16位字母和數字組合的字符串';
    			$ch_push = curl_init();
    			$options_push =  array(
    				CURLOPT_URL => $api_push,
    				CURLOPT_POST => true,
    				CURLOPT_RETURNTRANSFER => true,
    				CURLOPT_POSTFIELDS => implode("\n", $urls_push),
    				CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
    			);
    			curl_setopt_array($ch_push, $options_push);
    			$result_push = curl_exec($ch_push);
    			DB::update('baidu_push', ['updatetime' => time(), 'gxs' => $gxs, 'tjs' => $tjs], 'sid = '.$sid);
    		}
    	}
    } else {//不存在記錄 新增數據
    	$urls_push = array(
    		$baidu_push_url,
    	);
    	$api_push = 'http://data.zz.baidu.com/urls?site='.$_SERVER['HTTP_HOST'].'&token=這里是16位字母和數字組合的字符串';
    	$ch_push = curl_init();
    	$options_push =  array(
    		CURLOPT_URL => $api_push,
    		CURLOPT_POST => true,
    		CURLOPT_RETURNTRANSFER => true,
    		CURLOPT_POSTFIELDS => implode("\n", $urls_push),
    		CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
    	);
    	curl_setopt_array($ch_push, $options_push);
    	$result_push = curl_exec($ch_push);
    	$result_400 = str_replace('{"error":400,"message":"over quota"}',"400",$result_push);//獲取400狀態
    	if($result_400 == '400'){//提交失敗狀態0
    		DB::insert('baidu_push', ['url' => $baidu_push_url, 'dateline' => time(), 'updatetime' => time(), 'gxs' => '1', 'tjs' => '0', 'status' => '0']);
    	} else {//提交成功狀態1
    		DB::insert('baidu_push', ['url' => $baidu_push_url, 'dateline' => time(), 'updatetime' => time(), 'gxs' => '1', 'tjs' => '1', 'status' => '1']);
    	}
    }
    
    2、新建數據表 baidu_push
    字段說明:
    url = 鏈接地址
    dateline = 添加時間
    updatetime = 更新時間
    gxs = 更新次數
    tjs = 提交次數
    status = 狀態
    不懂可以聯系中文站長協助開發
    三、模板調用:
    1、php源碼調用:《改為<
    《?php include_once("baidu_push.php") ?》
    
    2、DZ論壇調用:
    {eval include TPLDIR.'/php/baidu_push.php';}
    
    3、百度主動推送:http://gongju.chinaadmin.cn/baidupush/
    4、百度自動提交:http://gongju.chinaadmin.cn/baidusubmit/
    編輯推薦
    在桌子上把腿张开调教
    <bdo id="ylihq"></bdo>
    <track id="ylihq"><div id="ylihq"></div></track>
      <track id="ylihq"><span id="ylihq"></span></track>

      <track id="ylihq"><div id="ylihq"></div></track>
      <track id="ylihq"></track>