Dream Sitemap Map Real time push to Baidu tutorial _php example

Source: Internet
Author: User
Tags error code explode

In the previous, dream a set of their own active ping Baidu plug-in, but later used, and finally Baidu launched a real-time push link address to Baidu, which is easier to use than Sitemap, but also to ensure the original article, the following I through the relevant information, According to Baidu's interface wrote a sitemap map real-time push to Baidu's approach, to share with you.

About weaving dream Baidu Real-time push I wrote two methods, we can choose:

1. Manually create a file, daily access to this file can be the day of all articles pushed to Baidu search engine. Create a tuisong.php access below the root directory will return the results of the Baidu interface

<?php require_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);/day start timestamp $dayEnd = Mktime (23,59,59, $month, $day, $year);/day end Timestamp $query = "Select Arch.id,types.typedir from Dede_arctype as types inner join dede_archives as arch on Types.id=arch.typeid where PU bdate< ". $dayEnd." and pubdate> ". $dayBegin." ";
Here Dede replace 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 ';
In the front of the site to replace their own site XXX replaced by their own key $ch = Curl_init (); $options = Array (curlopt_url => $api, curlopt_post => True, Curlopt_returntransfer => true, Curlopt_postfields => ("\ n", $urls), implode
=> 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:
Whether the field must be selected parameter type description
Success is the number of URL bars that int successfully pushed
Remain is the number of push URL bars remaining on 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 of illegal URL lists
Successful return Example:

Copy Code code as follows:

{
"Remain": 4999998,
"Success": 2,
"Not_same_site": [],
"Not_valid": []
}

Push failed

The status code is 4xx and the returned fields are:
Whether the field will be required type description
Error is int error code, same as status code
Message is a string error description
Failure return Example:

Copy Code code as follows:

{
"Error": 401,
' Message ': ' token is not valid '
}

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

Open the article_add.php file in the background of the dream. I found almost 262 lines.

Attention:
If you set the-core option on the system

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

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

Copy Code code as follows:

Please select your next action ". $result. $urls [0]." :

result is to see 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 is pushed, like I above to modify the article_edit.php is good.

The above is the entire 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.