PHP based on Curl initiative to push the latest content to Baidu included methods _php skills

Source: Internet
Author: User
Tags curl php example php programming php regular expression

This article describes the PHP based on Curl initiative to push the latest content to Baidu included methods. Share to everyone for your reference, specific as follows:

The benefits of PHP curl can be the fastest way and imitate the post to provide our URL address to Baidu search engine for collection.

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:

Push success:

The status code is 200, and the following fields may be returned:

Field Whether you must select Parameter type Description
Success Is Int Number of URL bars successfully pushed
Remain Is Int Number of push URL bars remaining on the same day
Not_same_site Whether Array List of URLs not processed due to this site URL
Not_valid Whether Array List of illegal URLs

Successful return Example:

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

Push failed:

The status code is 4xx and the returned fields are:

Field Whether must pass Type Description
Error Is Int Error code, same as status code
Message Is String Error description

Failure return Example:

{
 ' ERROR ': 401,
 ' message ': ' token is not valid '
}

More about PHP Interested readers can view the site topics: "Php Curl Usage Summary", "PHP array" operation Skills Daquan, "PHP Sorting algorithm Summary", "PHP common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", " PHP Programming algorithm Summary, "PHP Mathematical Calculation Skills Summary", "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string (String) Usage summary" and "PHP common database Operation skill Summary"

I hope this article will help you with the PHP program design.

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.