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

WBOY
Release: 2016-06-06 20:43:59
Original
1569 people have browsed it

域名 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>
Copy after login
Copy after login

存不存在 $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>
Copy after login
Copy after login

存不存在 $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>
Copy after login

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

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!