Home > Backend Development > PHP Tutorial > Detect whether the page is indexed by Baidu through curl in PHP_PHP Tutorial

Detect whether the page is indexed by Baidu through curl in PHP_PHP Tutorial

WBOY
Release: 2016-07-21 16:12:59
Original
844 people have browsed it

I need to organize the website recently, and I need to detect which pages in the website are not indexed by Baidu search engine and make relevant adjustments. Since I couldn’t see it clearly by using the site command one by one, I thought of using the PHP program to batch process it. After some research, I found that it is actually very simple. Here is the author’s implementation of using PHP to detect whether a page has been included in Baidu. Share the function.

The following is the specific code:

Copy code The code is as follows:

/*
* Detect whether the webpage is Baidu Included, return 1 means included, return 0 means not included
* @ param string $url URL to be detected
*/
function checkBaiduInclude($url){
$url='http:/ /www.baidu.com/s?wd='.$url;
$curl=curl_init();
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);
$rs=curl_exec($curl);
curl_close($curl);
if(!strpos($rs,'Sorry, not found')){
return 1;
}else{
return 0;
}
}

The meaning is very simple. For example, if you need to check whether the URL http://www.phpernote.com/javascript-function/833.html is included, you only need:

checkBaiduInclude('http://www.phpernote.com/javascript-function/833.html'); Check it out for yourself.

This article is reproduced from: PHP Programmer’s Notes

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/313563.htmlTechArticleI have to sort out the website recently. I need to detect which pages in the website have not been indexed by Baidu search engine so as to carry out relevant analysis. Adjustment. Because it’s really hard to see one by one using the site command...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template