Dream Sitemap Map Real-time push to Baidu tutorial _php example

Source: Internet
Author: User
In the past, weaving dream a set of their own active ping Baidu plug-ins, but later, Baidu launched a real-time push link address to Baidu, so much easier to use than sitemaps, but also to ensure that the original article, the following I through access to relevant information, According to the interface of Baidu wrote a sitemap map real-time push to Baidu's treatment method, share to everyone.

About weaving dream Baidu real-time push I wrote two ways, you can choose:

1. Manually create a file, daily access to this file can be the day all the articles pushed to Baidu search engine. After creating a tuisong.php access under the root directory, the results of Baidu interface 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,0,0, $month, $day, $year)///start timestamp $dayend = Mktime (23,59,59, $month, $day, $year);//end of day timestamp $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 by 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 ".", "; Replace the top http://baidub.com with your URL} $urls =substr ($urls, 0,-1), $urls = Explode (",", $urls); $api = ' http://data.zz.baidu.com /urls?site=www.baidu.com&token=hereistoken '; The front site is replaced by its own site XXX for its 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 success

The status code is 200, and the following fields may be returned:
field is a required parameter type description
Success is the number of URL bars successfully pushed by int
Remain is the number of available push URL bars for the day of int
Not_same_site A list of URLs that are not processed because they are not the site URL
Not_valid no array illegal URL list
Successful return Example:

Copy the Code code as follows:
{
"Remain": 4999998,
"Success": 2,
"Not_same_site": [],
"Not_valid": []
}

Push failed

The status code is 4xx and the return field is:
Whether a field is a mandatory type description
Error is an int fault code that is the same as the status code
Message is a string error description
Example of a failed return:

Copy the Code code as follows:
{
"Error": 401,
"Message": "token is not valid"
}

2, the second is to publish an article, like Baidu Push send once, this is more convenient, I am using this

Open the article_add.php file in the background of the dream. Find almost 262 rows

Attention:
If you set the-"core options"

If it is direct. Add the following code, or note the following hint

Baidu push $urls= "http://www.baidu.com". $artUrl;//before the domain name for your own if the above image is selected is to put "http://baidu.com". Remove $urls = Explode (",", $urls); $api = ' Http://data.zz.baidu.com/urls?site=www.0cx.cc&token=hereistoken '; The front site is replaced by its own site XXX for its 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 the addition of success, you can modify the following one or two lines of code like

Copy the Code code as follows:
Please select your next action ". $result. $urls [0]." :

Result is to look at the results of Baidu return, URLs are to see you push the URL.

Basically OK, if you want to change the article when the fact pushes, just like me above to modify article_edit.php just fine.

The above is the whole content of this article, I hope you like.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.