Home > php教程 > PHP源码 > body text

Baidu Sitemap pushes code in real time

大家讲道理
Release: 2016-11-08 17:39:13
Original
1566 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 string The site 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 the string access key for push applied on the webmaster platform

This method is only applicable to sites that have opened Baidu sitemap permissions. You can ping directly when the page is updated. 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 declared by Content-Length in the HTTP header is inconsistent with the length of the actual data sent

500 Webmaster platform server internal error

function tobaidu($url){
    $ntime=time();
    $now = date('Y-m-d',$ntime);
    $data =&#39;<?xml version="1.0" encoding="UTF-8"?>&#39;;
    $data .=&#39;   <urlset>&#39;;
    $data .=&#39;       <url>&#39;;
    $data .=&#39;           <loc><![CDATA[&#39;.$url.&#39;]]></loc>&#39;;
    $data .=&#39;           <lastmod>&#39;.$now.&#39;</lastmod>&#39;;
    $data .=&#39;           <changefreq>daily</changefreq>&#39;;
    $data .=&#39;           <priority>0.8</priority>&#39;;
    $data .=&#39;       </url>&#39;;
    $data .=&#39;   </urlset>&#39;;
 
    $pingurl="http://ping.baidu.com/sitemap?site=www.xxx.com&resource_name=sitemap&access_token=XXXXXXX";//你的接口地址
    $curl = curl_init(); // 启动一个CURL会话
    curl_setopt($curl, CURLOPT_URL, $pingurl); // 要访问的地址
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在
    curl_setopt($curl, CURLOPT_USERAGENT, "curl/7.12.1"); // 模拟用户使用的浏览器
    curl_setopt($curl, CURLOPT_COOKIE, $cookie);
    curl_setopt($curl, CURLOPT_REFERER,"");
    curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
    curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
    curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
    $tmpInfo = curl_exec($curl); // 执行操作
    if (curl_errno($curl)) {
       echo &#39;Errno&#39;.curl_error($curl);//捕抓异常
    }
    curl_close($curl); // 关闭CURL会话
    return $tmpInfo; // 返回数据
}
 
$tt= tobaidu("http://www.appleshu.com/");
Copy after login


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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!