Home > Backend Development > PHP Tutorial > Baidu Sitemap pushes code in real time

Baidu Sitemap pushes code in real time

WBOY
Release: 2016-07-25 08:48:02
Original
1408 people have browsed it
Interface calling address: http://ping.baidu.com/sitemap?site=www.xxx.com&resource_name=sitemap&access_token=XXXXXXX
Parameter
site is a string of sites verified on the webmaster platform, such as www.example.com
resource_name You The name of the data that is allowed to be pushed, such as RDF_BBS_Thread or sitemap
access_token is a string. The access key for push applied on the webmaster platform

This method is only applicable to sites that have opened Baidu sitemap permissions. When the page is updated, you can ping directly. To Baidu. Can be viewed in Baidu backend

Feedback code

200 No usage error, need to further observe whether the returned content is correct
400 Required parameters are not provided
405 Unsupported request method, we only support POST method to submit data
411 HTTP The Content-Length field is missing in the header
413 The pushed data is too large and exceeds the 10MB limit
422 The length of the Content-Length declaration in the HTTP header is inconsistent with the length of the actual data sent
500 Webmaster Platform server internal error

www. code provided by appleshu.com apple novel network
  1. function tobaidu($url){
  2. $ntime=time();
  3. $now = date('Y-m-d',$ntime);
  4. $data ='';
  5. $data .=' ';
  6. $data .=' ';
  7. $data .=' ';
  8. $data .=' '.$now.'';
  9. $data .=' ';
  10. $data .=' 0.8';
  11. $data .=' ';
  12. $data .=' ';
  13. $pingurl="http://ping.baidu.com/sitemap?site=www.xxx.com&resource_name=sitemap&access_token=XXXXXXX";//Your interface address
  14. $curl = curl_init(); // Start A CURL session
  15. curl_setopt($curl, CURLOPT_URL, $pingurl); // The address to be accessed
  16. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // Check the source of the authentication certificate
  17. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1) ; // Check whether the SSL encryption algorithm exists from the certificate
  18. curl_setopt($curl, CURLOPT_USERAGENT, "curl/7.12.1"); // Simulate the browser used by the user
  19. curl_setopt($curl, CURLOPT_COOKIE, $cookie);
  20. curl_setopt($curl, CURLOPT_REFERER,"");
  21. curl_setopt($curl, CURLOPT_POST, 1); // Send a regular Post request
  22. curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post submitted data packet
  23. curl_setopt($curl, CURLOPT_TIMEOUT, 30); // Set timeout limit to prevent infinite loop
  24. curl_setopt($curl, CURLOPT_HEADER, 0); // Display the content of the returned Header area
  25. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // The obtained information is returned in the form of a file stream
  26. $tmpInfo = curl_exec($curl); //Perform the operation
  27. if (curl_errno($curl)) {
  28. echo 'Errno'.curl_error($curl);//Catch exceptions
  29. }
  30. curl_close($curl); // Close CURL session
  31. return $tmpInfo; // Return data
  32. }
  33. $tt= tobaidu("http://www.appleshu.com/");
Copy Code
Baidu Sitemap pushes code in real time


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