一般的网站建设之类的公司的网站上都有域名注册和虚拟主机这种功能;关于这个域名注册,有几个问题
第一,去哪儿查询某个域名是否已被注册?有没有相应的API供调用?
第二,上面这玩艺儿是免费的吗?
第三,虚拟主机这种功能如何实现的?PHP代码中需要做些什么?严重感谢,呼唤高人前来。

解决方案 »

  1.   

    这种API一般需要收费的,或者只对下级代理之类的开放,个人暂时不知道哪里有免费的api提供当然间接,可以通过查whois来做,比如.cn的,不同的后缀查询地址是不一样的
    $domain = 'tianya.cn';
    $server = 'whois.cnnic.net.cn';
    $fp = fsockopen($server, 43);
    fwrite($fp, $domain."\r\n");
    $str = '';
    while (!feof($fp))
    {
    $str .= fgets($fp, 1024);
    }
    fclose($fp);
    echo $str;
      

  2.   

    发个很早很早以前的。全都是用的专业接口。
    不知道现在还能用不。
    只有自己测试下了。
    whois_cn.php<?
    class domain{
    var $domain="";
    function search_cn()
    {
    $return_result=array();
    $domains=split("\.",$this->domain);
            if(count($domains)>2){
                $domain=$domains[0];
                for($i=1;$i<count($domains);$i++){
                    if($i==1){
                       $ext=$domains[$i];
                    }else{
                       $ext.=".".$domains[$i];
                    }
                 }
            }else{
                $domain=$domains[0];
                $ext=$domains[1];
            }
    $S_key=array("\\",'&',' ',"'",'"','/','*',',','<','>',"\r","\t","\n",'#','_','.');
    foreach($S_key as $value){
    if (strpos($domain,$value)!==false){ 
    $return_result["chk"]=0;
    $return_result["str"]="域名格式错误";
    return $return_result;
    }
    }
    $ext1=urlencode($ext);
    $domain=urlencode($domain);

    if($ext=="中国"||$ext=="网络"||$ext=="公司"){
    $req  =  "suffix[]=.$ext1&Domain=$domain";
    $header .= "POST /src/cn_step1.php3 HTTP/1.0\r\n";   
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";   
    $header .= "Content-Length: ".strlen($req)."\r\n\r\n"; 
    $fp = @fsockopen('www.xinnet.com',80);
    if(!$fp){
    $return_result["chk"]=0;
    $return_result["str"]="连接查询服务器失败";
    return $return_result;
    }else{
    try{
    fputs($fp,$header.$req);
    }catch (Exception $e){ 
    $return_result["chk"]=0;
    $return_result["str"]="发生未知错";
    return $return_result;
    }
    while($result=fgets($fp)){
    $res.=$result;
    }
    fclose($fp);
    $res=strip_tags($res);
    if(preg_match("/已被注册/i",$res)){//已注册
    $whois_result["chk"]=1;
    $whois_result["str"]="已经被注册";
    return $whois_result;
    }else{//未注册
    $whois_result["chk"]=2;
    $whois_result["str"]="没有被注册";
    return $whois_result;
    }
    }
    }else{
    //module=chinesesearch         //国内
    //module=interchinesesearch    //国际
    $fp=@fopen("http://www.53dns.com/domain_reg/index.asp?searchType=IntDomain&action=check&module=interchinesesearch&suffix=.$ext&searchedDomainName=$domain",rb);
    if(!$fp){
    $return_result["chk"]=0;
    $return_result["str"]="连接查询服务器失败";
    return $return_result;
    }else{
    while(!feof($fp)){
    $res .= fread($fp,1024);
    }
    $res = strip_tags($res);
    if(preg_match("/已经被注册/i",$res)){//已注册
    $whois_result["chk"]=1;
    $whois_result["str"]="已经被注册";
    return $whois_result;
    }else{//未注册
    $whois_result["chk"]=2;
    $whois_result["str"]="没有被注册";
    return $whois_result;
    }
    }
    }
    }
    }
    ?>
      

  3.   


    whois_en.php<?
    class domain{
        var $domain="";
        var $servers=array(
              array("biz","whois.neulevel.biz","not found"),
                    array("cc","whois.nic.cc","no match"),
                    array("cn","whois.cnnic.net.cn","no matching record"),
                    array("com","whois.crsnic.net","no match"),
    array("mobi","whois.hichina.com","not found"),
    array("name","whois.hichina.com","no match"),
                    array("com.cn","whois.cnnic.net.cn","no matching record"),
                    array("info","whois.afilias.net","not found"),
                    array("net","whois.crsnic.net","no match"),
                    array("net.cn","whois.cnnic.net.cn","no matching record"),
                    array("org","whois.publicinterestregistry.net","not found"),
                    array("org.cn","whois.cnnic.net.cn","no matching record"),
    array("gov.cn","whois.cnnic.net.cn","no matching record"),
    array("edu","whois.educause.net","no match"),
                    array("tv","whois.nic.tv","no match"),
            );
        function info(){
            if($this->is_valid()){
                $tldname=$this->get_tld();
                $domainname=$this->get_domain();
                $whois_server=$this->get_whois_server();
    $return_result=array();
                if($whois_server!=""){
    try{
                     $fp = fsockopen($whois_server,43);
    }catch (Exception $e){
    $return_result["chk"]=0;
    $return_result["str"]="连接查询服务器失败";
    return $return_result;
    }
    if(!$fp){
    $return_result["chk"]=0;
    $return_result["str"]="连接查询服务器失败";
    return $return_result;
    }

                    $dom=$domainname.".".$tldname;
    try{
                     fputs($fp, "$dom\r\n");
    }catch (Exception $e){ 
    $return_result["chk"]=0;
    $return_result["str"]="发生未知错";
    return $return_result;
    }
                    $string="";
                    while(!feof($fp)){
                        $string.=fgets($fp,128);
                    }
                    fclose($fp);
    $return_result["chk"]=1;
    $return_result["str"]=$string;
    return $return_result;
                }else{
    $return_result["chk"]=0;
    $return_result["str"]="没有可查询的服务器";
    return $return_result;
                }
            }else{
    $return_result["chk"]=0;
    $return_result["str"]="输入的域名格式不正确";
    return $return_result;
            }
        }    function html_info(){
            return nl2br($this->info());
        }    function get_whois_server(){
            $tldname=$this->get_tld();
            for($i=0;$i<count($this->servers);$i++){
                if($this->servers[$i][0]==$tldname){
                    $server=$this->servers[$i][1];
                    $full_dom=$this->servers[$i][3];
                }
            }
            return $server;
        }    function get_tld(){
           $domain=split("\.",$this->domain);
           if(count($domain)>2){
               $domainname=$domain[0];
               for($i=1;$i<count($domain);$i++){
                   if($i==1){
                      $tldname=$domain[$i];
                   }else{
                      $tldname.=".".$domain[$i];
                   }
                }
           }else{
               $domainname=$domain[0];
               $tldname=$domain[1];
           }
           return $tldname;
        }    function get_tlds(){
         $tlds="";
            for($i=0;$i<count($this->servers);$i++){
                $tlds[$i]=$this->servers[$i][0];
            }
            return $tlds;
        }    function get_domain(){
           $domain=split("\.",$this->domain);
           return $domain[0];
        }    function get_notfound_string(){
           $tldname=$this->get_tld();
           for($i=0;$i<count($this->servers);$i++){
               if($this->servers[$i][0]==$tldname){
                   $notfound=$this->servers[$i][2];
               }
           }
           return $notfound;
        }    function is_available(){
    $whois_result=$this->info();
            $whois_string=$whois_result["str"];
    $whois_chk=(int)$whois_result["chk"];

    if($whois_chk==1){//在服务器上查询成功才验证是否被注册
    if(trim($whois_string)==""){
    $whois_result["chk"]=0;
    $whois_result["str"]="超时,服务器未返回结果";
    return $whois_result;
    }
    $not_found_string=$this->get_notfound_string();
    $domain=$this->domain;
    if(preg_match("/".$not_found_string."/i",$whois_string)){//未注册
    $whois_result["chk"]=2;
    $whois_result["str"]="";
    $whois_result["str"]= $whois_string;
    return $whois_result;
    }else{//已注册
    $whois_result["chk"]=1;
    $whois_result["str"]="";
    $whois_result["str"]= $whois_string;
    return $whois_result;
    }
    }else{
    return $whois_result;
    }
        }    function is_valid(){
    if(ereg("^[a-zA-Z0-9\-]{1,}$",$this->get_domain()) && !preg_match("/--/",$this->get_domain())){
    return true;
    }else{
    return false;
    }
        }
    }
    ?>
      

  4.   

    whois_mod.php<?
    class domain{
        var $domain="";
    var $checked="";
        var $servers=array(
              array("biz","whois.neulevel.biz","not found"),
                    array("cc","whois.nic.cc","no match"),
                    array("cn","whois.cnnic.net.cn","no matching record"),
                    array("com","whois.crsnic.net","no match"),
    //array("mobi","whois.internic.net","no match"),
                    array("com.cn","whois.cnnic.net.cn","no matching record"),
                    array("info","whois.afilias.net","not found"),
                    array("net","whois.crsnic.net","no match"),
                    array("net.cn","whois.cnnic.net.cn","no matching record"),
                    array("org","whois.publicinterestregistry.net","not found"),
                    array("org.cn","whois.cnnic.net.cn","no matching record"),
    array("gov.cn","whois.cnnic.net.cn","no matching record"),
    array("edu","whois.educause.net","no match"),
                    array("tv","whois.nic.tv","no match"),
    //array("中国","whois.cnnic.net.cn","no matching record"),
    //array("网络","whois.cnnic.cn","no matching record"),
    //array("公司","whois.cnnic.cn","no matching record")
            );
        function info(){
            if($this->is_valid()){
                $tldname=$this->get_tld();
                $domainname=$this->get_domain();
                $whois_server=$this->get_whois_server();
    $return_result=array();
                if($whois_server!=""){
    try{
                     $fp = @fsockopen($whois_server,43);
    }catch (Exception $e){
    $return_result["chk"]=0;
    $return_result["str"]="连接查询服务器失败";
    return $return_result;
    }
    if(!$fp){
    $return_result["chk"]=0;
    $return_result["str"]="连接查询服务器失败";
    return $return_result;
    }

                    $dom=$domainname.".".$tldname;
    try{
                     fputs($fp, "$dom\r\n");
    }catch (Exception $e){ 
    $return_result["chk"]=0;
    $return_result["str"]="发生未知错";
    return $return_result;
    }
                    $string="";
                    while(!feof($fp)){
                        $string.=fgets($fp,128);
                    }
                    fclose($fp);
    $return_result["chk"]=1;
    $return_result["str"]=$string;
    return $return_result;
                }else{
    $return_result["chk"]=0;
    $return_result["str"]="没有可查询的服务器";
    return $return_result;
                }
            }else{
    $return_result["chk"]=0;
    $return_result["str"]="输入的域名格式不正确";
    return $return_result;
            }
        }    function html_info(){
            return nl2br($this->info());
        }    function get_whois_server(){
            $tldname=$this->get_tld();
            for($i=0;$i<count($this->servers);$i++){
                if($this->servers[$i][0]==$tldname){
                    $server=$this->servers[$i][1];
                    $full_dom=$this->servers[$i][3];
                }
            }
            return $server;
        }    function get_tld(){
           $domain=split("\.",$this->domain);
           if(count($domain)>2){
               $domainname=$domain[0];
               for($i=1;$i<count($domain);$i++){
                   if($i==1){
                      $tldname=$domain[$i];
                   }else{
                      $tldname.=".".$domain[$i];
                   }
                }
           }else{
               $domainname=$domain[0];
               $tldname=$domain[1];
           }
           return $tldname;
        }    function get_tlds(){
         $tlds="";
            for($i=0;$i<count($this->servers);$i++){
                $tlds[$i]=$this->servers[$i][0];
            }
            return $tlds;
        }    function get_domain(){
           $domain=split("\.",$this->domain);
           return $domain[0];
        }    function get_notfound_string(){
           $tldname=$this->get_tld();
           for($i=0;$i<count($this->servers);$i++){
               if($this->servers[$i][0]==$tldname){
                   $notfound=$this->servers[$i][2];
               }
           }
           return $notfound;
        }    function is_available(){
    $whois_result=$this->info();
            $whois_string=$whois_result["str"];
    $whois_chk=(int)$whois_result["chk"];

    if($whois_chk==1){//在服务器上查询成功才验证是否被注册
    if(trim($whois_string)==""){
    $whois_result["chk"]=0;
    $whois_result["str"]="超时,服务器未返回结果";
    return $whois_result;
    }
    $not_found_string=$this->get_notfound_string();
    $domain=$this->domain;
    if(preg_match("/".$not_found_string."/i",$whois_string)){//未注册
    $whois_result["chk"]=2;
    $whois_result["str"]="";
    $whois_result["str"]= $whois_string;
    return $whois_result;
    }else{//已注册
    $whois_result["chk"]=1;
    $whois_result["str"]="";
    $whois_result["str"]= $whois_string;
    return $whois_result;
    }
    }else{
    return $whois_result;
    }
        }    function is_valid(){
    if($this->checked){
    if(ereg("^[a-zA-Z0-9\-]{3,}$",$this->get_domain()) && !preg_match("/--/",$this->get_domain())){
    return true;
    }else{
    return false;
    }
    }else{
    $S_key=array("\\",'&',' ',"'",'"','/','*',',','<','>',"\r","\t","\n",'#','_');
    foreach($S_key as $value){
    if (strpos($this->get_domain(),$value)!==false){ 
    return false;
    }
    }
    return true;
    }
        }
    }
    ?>