PHPCMS implementation of automatic push URL to Baidu webmaster platform

Source: Internet
Author: User
Tags curl php file php example


Baidu Webmaster Platform Open URL Push interface, you can use the form of the call interface to actively and timely push the URL to Baidu, the following demo in the PHPCMS system to use the interface to automatically push URLs to Baidu webmaster platform.


Add a Baidu push function to the phpcms libs/functions/global.func.php file:


/**
* Baidu Webmaster Platform link push
* @param $bdurls URL Array
* @date 2015.8.8 15:19
*/
function Push_baidu ($bdurls) {
$api = ' http://data.zz.baidu.com/urls?site=www.dayecn.com&token= to Baidu Webmaster platform to get ';
$ch = Curl_init ();
$options = Array (
Curlopt_url => $api,
Curlopt_post => True,
Curlopt_returntransfer => True,
Curlopt_postfields => implode ("\ \", $bdurls),
Curlopt_httpheader => Array (' Content-type:text/plain '),
);
Curl_setopt_array ($ch, $options);
$result = curl_exec ($ch);
$result = Json_decode ($result, 1);
return $result;
}

You can call this method when you need to push the action, such as publishing an article, modifying an article, or generating a static article page. For example, I want to call this interface in a batch generation static page, go to the modules/content/crete_html.php file Batch_show method, invoke the method defined above:

foreach ($rs as $r) {
if ($r [' Islink ']) continue;
$this->db->table_name = $tablename;
$r 2 = $this->db->get_one (array (' ID ' => $r [' id ']);
if ($r 2) $r = Array_merge ($r, $r 2);
Determine if the data is upgraded or converted.
if (! $r [' upgrade ']) {
$urls = $this->url->show ($r [' id '], ', $r [' catid '], $r [' inputtime ']);
} else {
$urls [1] = $r [' url '];
}
$bdurls [] = $r [' url '];
$this->html->show ($urls [1], $r, 0, ' edit ', $r [' upgrade ']);
}
Push Baidu Platform
$push _result = Push_baidu ($bdurls);
$msg = ';
if ($push _result[' success '] < 1) {
$msg = ' Baidu alliance push link failed! ';
}
The last few lines are modified after the new code, the first to update which static pages of the URL into the array, and then call this method to pass parameters.

To push when other actions such as adding or editing an article, the principle is the same, find the corresponding place to call the push method on the line

Baidu Link submitted three ways:

1, the initiative to push: the most rapid way of submission, recommend that you will be the site of the new output link immediately through this way to Baidu, to ensure that the new link can be included in time Baidu.

2, Sitemap: You can regularly put the site link to the sitemap, and then submit the Sitemap to Baidu. Baidu will periodically crawl check your submitted sitemap, the link in which to deal with, but included slower than the active push.

3, hand-submitted: One-time submit link to Baidu, you can use this way.


Here's how to use the Curl active push link with the PHP example, using the Curl extension:

$urls = Array (
' Http://www.example.com/1.html ',
' Http://www.example.com/2.html ',
);
$api = ' Http://data.zz.baidu.com/urls?site=www.dayecn.com&token=Db0ZoYUOwUyEp87Z ';
$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;
First of all, Baidu Webmaster platform to verify the site, and then get token key, only the right to push the URL to Baidu. Baidu Webmaster Platform: http://zhanzhang.baidu.com

You can publish an article when the URL of this article to the Baidu Webmaster platform, or bulk push, through the return of the $result state to determine whether the push is successful, the return status code description:

field is required parameter type description
Success is int the number of URL bars successfully pushed
remain is int The number of push URL bars remaining on the same day
Not_sa Me_site no array URL list not processed because it is not a local URL
not_valid no array illegal URL list

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.