This article describes how to push the map of Zhimeng sitemap to Baidu in real time. if you need it, you can refer to the previous tutorials. Zhimeng has a set of plug-ins that can actively ping Baidu, but it will not be used later, finally, Baidu launched a real-time push link address to Baidu, which is much more convenient and easier to use than sitemap, and can ensure the original article. below I will refer to the relevant materials, according to Baidu's interface, I wrote a solution to push sitemap to Baidu in real time and shared it with you.
I have written two methods for Zhimeng's Baidu real-time push:
1. manually create a file. when you access this file every day, you can push all the articles of the day to Baidu search engine. after you create a tuisong. php file under the root directory, Baidu interface results will be returned.
<? Phprequire_once ("include/common. inc. php "); require_once" include/arc. partview. class. php "; require_once ('include/charset. func. php '); $ year = date ("Y"); $ month = date ("m"); $ day = date ("d "); $ dayBegin = mktime (, 0, $ month, $ day, $ year); // The start timestamp of the day $ dayEnd = mktime (, 59, $ month, $ day, $ year); // The end timestamp of the day $ query = "SELECT arch. id, types. typedir FROM dede_arctype as types inner join dede_archives as arch on types. id = arch. typeid where pubdate <". $ dayEnd. "AND pubdate> ". $ dayBegin. ""; // Here, dede is replaced with your own table prefix $ urls = ""; $ dsql-> Execute ('arch. id, types. typedir ', $ query); while ($ row = $ dsql-> GetArray ('arch. id, types. typedir ') {$ urls. =" http://www.baidu.com ". Str_replace ("{cmspath}", "", $ row ['typedir']). "/". $ row [id]. ". html ". ","; // Set http://baidub.com Change to your URL} $ urls = substr ($ urls, 0,-1); $ urls = explode (",", $ urls); $ api =' http://data.zz.baidu.com/urls?site=www.baidu.com&token=hereistoken '; // Replace the front site with your own site xxx with your own key $ 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); echo $ result. count ($ urls);?>
View push feedback
Push successful
If the status code is 200, the following fields may be returned:
Description of required parameter types
Success is the number of successfully pushed URLs by int.
Remain is the number of remaining push URLs on the day of int.
Not_same_site no array list of URLs not processed because it is not the site url
Not_valid no array illegal url list
Success response example:
The code is as follows:
{
"Remain": 4999998,
"Success": 2,
"Not_same_site": [],
"Not_valid": []
}
Push failed
The status code is 4xx, and the returned fields include:
Required field type description
Error is an int error code, which is the same as the status code.
Message is a string error description.
Example of failure response:
The code is as follows:
{
"Error": 401,
"Message": "token is not valid"
}
2. The second is to publish an article, just like Baidu push once. this is more convenient and I use this
Open the article_add.php file in the background of Zhimeng. find the 262 rows.
Note:
If you set the-core options
If you want to directly add the following code, otherwise note the following prompt:
// Baidu push $ urls = "http://www.baidu.com ". $ artUrl; // replace the previous domain name with your own ". remove $ urls = explode (",", $ urls); $ api = 'http: // data.zz.baidu.com/urls? Site = www.0cx. cc & token = hereistoken '; // replace the front site with your own site xxx with your own key $ 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 );
OK. if you want to see if the code is successfully added, you can modify the following one or two lines of code.
The code is as follows:
Please select your subsequent operations ". $ result. $ urls [0].":
The result is the result returned by Baidu, and the urls is the url you pushed.
Basically, it's okay. if you want to push the fact when you modify the article, you just need to modify article_edit.php like above.
The above is all the content of this article. I hope you will like it.