百度自动ping功能javascript和php代码

 
更多

百度自动ping功能javascript和php代码

百度自动ping功能对SEO有不少帮助,在这收藏一下百度官方页的javascript代码和PHP代码.

百度官方的ping功能javascript代码:

 

<script>
 function pin(url,value){
  var request = null;
   try{
    var request=new XMLHttpRequest();
   }
   catch(e){}
   if(request==null) try {
    request = new ActiveXObject(“Microsoft.XMLHTTP”);
   }catch (e) {}
   if(request==null) try {
    request=new ActiveXObject(“MSXML2.XMLHTTP.3.0″);
    }catch (e) {}
   if(request==null) try {
   request=new ActiveXObject(“Msxml2.XMLHTTP”);
   }catch (e) {}

   var values=”<?xml version=\”1.0\”?>\n<methodCall>\n<methodName>weblogUpdates.ping</methodName>\n<params>\n<param>\n<value><string>”+value+”</string></value>\n</param><param><value><string>”+value+”</string></value>\n</param>\n</params>\n</methodCall>”;
  
  request.onreadystatechange = function(){
    if (request.readyState == 4) {
             if (request.status == 200) {
                 
   document.getElementById(“alert1″).style.display=”none”;
   document.getElementById(“alert2″).style.display=”inline”;
   document.getElementById(“alert3″).style.display=”none”;
   
              }
              else {
               
   document.getElementById(“alert1″).style.display=”none”;
   document.getElementById(“alert2″).style.display=”none”;
   document.getElementById(“alert3″).style.display=”inline”; 
   
             }
          }
  }
  
  request.open(“POST”, url);
  request.setRequestHeader(“Content-Type”, “text/xml”);
  request.send(values);
 }
 function check_form(){
  
  var sUrl=document.getElementById(“url”);
  
  if(sUrl.value==”" || sUrl.value==”http://”){
   document.getElementById(“alert1″).style.display=”inline”;
   document.getElementById(“alert2″).style.display=”none”;
   document.getElementById(“alert3″).style.display=”none”;

  }else{
   pin(“/ping/RPC2″,sUrl.value); 
  }
 }
</script>

PHP代码为:

    <?php
    function postUrl($url, $postvar)
    {
        $ch = curl_init();
        $headers = array(
            “POST “.$url.” HTTP/1.0″,
            “Content-type: text/xml; charset=\”utf-8\”",
            “Accept: text/xml”,
            “Content-length: “.strlen($postvar)
        );
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postvar);
        $res = curl_exec ($ch);
        curl_close ($ch);
        return $res;
    }

    $baiduXML = “<?xml version=\”1.0\” encoding=\”utf-8\”?>
       <methodCall>
       <methodName>weblogUpdates.extendedPing</methodName>
       <params>
       <param><value><string>$url</string></value></param>
       <param><value><string>$url</string></value></param>
       </params>
       </methodCall>”;
    $res = postUrl(‘http://ping.baidu.com/ping/RPC2′, $baiduXML);
    ?>
打赏

本文固定链接: https://www.cxy163.net/archives/644 | 绝缘体

该日志由 绝缘体.. 于 2012年05月07日 发表在 PHP, 囤技术, 首页 分类下,
原创文章转载请注明: 百度自动ping功能javascript和php代码 | 绝缘体
关键字: , , ,

报歉!评论已关闭.