Heim  >  Artikel  >  Backend-Entwicklung  >  关于域名CNAME后服务器能否获得原址?

关于域名CNAME后服务器能否获得原址?

WBOY
WBOYOriginal
2016-06-06 20:43:591569Durchsuche

域名 www.blog.com CNAME至 123.xx.com,也能可能CNAME至345.xx.com,
服务器接收到 www.blog.com/1的请求,服务器能得到域名 345.xx.com或者123.xx.com 吗?

<code><?php if($origin == '123.xx.com'){
        //todo 
    }

</code></code>

存不存在 $origin? 存在的话怎么得到$origin ? 谢谢

回复内容:

域名 www.blog.com CNAME至 123.xx.com,也能可能CNAME至345.xx.com,
服务器接收到 www.blog.com/1的请求,服务器能得到域名 345.xx.com或者123.xx.com 吗?

<code><?php if($origin == '123.xx.com'){
        //todo 
    }

</code></code>

存不存在 $origin? 存在的话怎么得到$origin ? 谢谢

可以。服务器解析目标域名(www.blog.com)会得到 CNAME 到 www.xx.com 的结果。

<code class="lang-php"><?php var_dump(dns_get_record('www.baidu.com', DNS_A));
// returns
array(2) {
  [0]=>
  array(5) {
    ["host"]=>
    string(16) "www.a.shifen.com"
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(267)
    ["type"]=>
    string(1) "A"
    ["ip"]=>
    string(14) "61.135.169.105"
  }
  [1]=>
  array(5) {
    ["host"]=>
    string(16) "www.a.shifen.com"
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(267)
    ["type"]=>
    string(1) "A"
    ["ip"]=>
    string(14) "61.135.169.125"
  }
}
</code>

在服务器端应该不能直接得到CNAME的域名,因为CNAME解析是在DNS解析步骤完成的,服务器只会得到请求host,在服务器这边恐怕不能直接根据CNAME的域名做处理;
如果想得到DNS记录,可以借助楼上的方式,使用相应语言的函数发送请求得出。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn