PHPCMS automatically pushes URLs to Baidu webmaster platform-PHP source code

Source: Internet
Author: User
Tags php example
Let's take a look at an article about automatically pushing URL to the Baidu webmaster platform using PHPCMS. I hope this tutorial will help you. Let's take a look at an article about automatically pushing URL to the Baidu webmaster platform using PHPCMS. I hope this tutorial will help you.

Script ec (2); script


The url push interface is opened on the Baidu webmaster platform. You can actively push the url to Baidu in a timely manner by calling the interface. The following shows how to use the interface to automatically push the URL to the Baidu webmaster platform in the PHPCMS system.


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


/**
* Baidu webmaster platform link push
* @ Param $ bdurls url Array
* @ Date 15:5.8.8
*/
Function push_baidu ($ bdurls ){
$ Api = 'HTTP: // data.zz.baidu.com/urls? Site = www.dayecn.com & token = go to Baidu webmaster platform to get it ';
$ Ch = curl_init ();
$ Options = array (
CURLOPT_URL => $ api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => implode ("\ n", $ 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 actions, such as publishing an article, modifying an article, or generating a static Article Page. For example, if I want to call this interface in the place where static pages are generated in batches, go to the batch_show method of the modules/content/crete_html.php file and call the method defined above:

Foreach ($ rs as $ r ){
If ($ r ['islink']) continue;
$ This-> db-> table_name = $ tablename;
$ R2 = $ this-> db-> get_one (array ('id' => $ r ['id']);
If ($ r2) $ r = array_merge ($ r, $ r2 );
// Determine whether 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 the newly added code after modification. First, you need to put the updated Static Page URLs into the array and then call this method to pass the parameters.

The push principle is the same for other actions such as adding or editing an article. Just find the corresponding place and call the push method.

Baidu link submission methods:

1. proactive push: the fastest submission method. We recommend that you push the new site production link to Baidu immediately on the same day to ensure that the new link can be indexed by Baidu in a timely manner.

2. sitemap: You can regularly store website links in sitemap and submit sitemap to Baidu. Baidu periodically crawls and checks the submitted sitemap to process the links, but the indexing speed is slower than the active pushing speed.

3. Manual submission: one-time submission link to Baidu. This method can be used.


The following describes the PHP example of using curl to actively push links, using 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 ("\ n", $ urls ),
CURLOPT_HTTPHEADER => array ('content-Type: text/plain '),
);
Curl_setopt_array ($ ch, $ options );
$ Result = curl_exec ($ ch );
Echo $ result;
First, you must verify the site on the Baidu webmaster platform, and then obtain the token key to have the permission to push the url to Baidu. Baidu webmaster platform: http://zhanzhang.baidu.com

When publishing an article, you can push the url of this article to the Baidu webmaster platform, or batch push, and determine whether the push is successful by returning the $ result status. The returned status code is described as follows:

Field Required Parameter type Description
Success Yes Int Number of successfully pushed URLs
Remain Yes Int Number of remaining push URLs on the current day
Not_same_site No Array List of URLs not processed because it is not the site url
Not_valid No Array Invalid 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.