Many webmasters dream of having their websites indexed by well-known engines like Baidu. Here, Baidu provides the Baidu Webmaster tool for submitting your website, and it also offers an API interface that allows programs to automatically submit website page URLs.

Code

The official Baidu Webmaster also provides PHP version code, which this code optimizes and improves upon the Baidu code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$site = "Website Address";
$token = "Baidu Webmaster Token";
$urls = array() // All page addresses must be in this array
$api = "http://data.zz.baidu.com/urls?site=$site&token=$token";
$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);
curl_close($ch);
$success = json_decode($result)->success;
if($success){
echo "Push Successful";
}
else{
echo "Push Failed";
}

For specific return information, refer to Baidu Webmaster.

image-20230101215103024