The following gives a PHP function, the function is to detect whether a Web page is included in Baidu, directly give the code
Use: Incoming a URL, such as http://www.jbxue.com/article/1.html, returned 1, Representative has been included, returned 0, on behalf of Baidu did not include.
Copy code code as follows:
<?php
Header ("content-type:text/html; Charset=utf-8 ");
function Checkbaidu ($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);
$arr = Parse_url ($url);
if (Strpos ($arr [' Query '], ' http://')) {
$arr [' query '] = str_replace (' http://', ', ', Str_replace (' wd= ', ', ', $arr [' query ']);
} else {
$arr [' query '] = Str_replace (' wd= ', ', ', $arr [' query ']);
}
if (Strpos ($arr [' Query '], '? ')) {
$str = strstr ($arr [' Query '], '? ');
$arr [' query '] = Str_replace ($str, ', $arr [' query ']);
}
if (Strpos ($arr [' Query '], '/')) {
$narr = explode ('/', $arr [' query ']);
$arr [' query '] = $narr [0];
}
if (Strpos ($rs, ' <b> ') $arr [' Query ']. ' </b> ')) {
return 1;
} else {
return 0;
}
}
echo Checkbaidu (' http://www.jbxue.com/article/1.html ');
?>
Execution results:
1