我checkdnsrr在Windows上使用PHP 5.3,它总是返回false.
dns_get_record但是,有效.
echo ("test.com dns check: ". checkdnsrr("test.com","NS")); //false!!
print_r(dns_get_record("test.com",DNS_NS)); //returns the right data
Run Code Online (Sandbox Code Playgroud)
我想我发现了一些东西(在 Windows、PHP 5.3.0、CLI 上尝试过):
当我这样做时:
$tests = array('A', 'MX', 'NS', 'SOA', 'PTR', 'CNAME', 'AAAA', 'A6', 'SRV', 'NAPTR', 'TXT', 'ANY');
foreach ($tests as $type) {
echo " Type = $type : ";
var_dump(checkdnsrr("test.com", $type));
}
Run Code Online (Sandbox Code Playgroud)
我明白了:
C:\bin\php-5.3\tests>c:\bin\php-5.3\php.exe test-dns.php
bool(true)
test.com dns check:
Type = A : bool(false)
Type = MX : bool(false)
Type = NS : bool(false)
Type = SOA : bool(false)
Type = PTR : bool(false)
Type = CNAME : bool(false)
Type = AAAA : bool(false)
Type = A6 : bool(false)
Type = SRV : bool(false)
Type = NAPTR : bool(false)
Type = TXT : bool(false)
Type = ANY : bool(false)
Run Code Online (Sandbox Code Playgroud)
因此,没有一个测试给出“true”:-(
但是当我尝试使用另一个域时:
$tests = array('A', 'MX', 'NS', 'SOA', 'PTR', 'CNAME', 'AAAA', 'A6', 'SRV', 'NAPTR', 'TXT', 'ANY');
foreach ($tests as $type) {
echo " Type = $type : ";
var_dump(checkdnsrr("pascal-martin.fr", $type));
}
Run Code Online (Sandbox Code Playgroud)
(对此进行测试是因为我知道上面有什么,并且想测试特定的想法^^)
我得到:
C:\bin\php-5.3\tests>c:\bin\php-5.3\php.exe test-dns.php
bool(true)
test.com dns check:
Type = A : bool(true)
Type = MX : bool(true)
Type = NS : bool(true)
Type = SOA : bool(true)
Type = PTR : bool(true)
Type = CNAME : bool(true)
Type = AAAA : bool(true)
Type = A6 : bool(true)
Type = SRV : bool(true)
Type = NAPTR : bool(true)
Type = TXT : bool(true)
Type = ANY : bool(true)
Run Code Online (Sandbox Code Playgroud)
所以,该功能似乎正在工作......至少对于某些领域!
为什么会这样呢?
也许 test.com 的 DNS 服务器上未配置某些内容?并且在 pascal-martin.fr 上配置了某些内容?
我不太了解 DNS 系统,无法判断:-(
以下是一些命令(来自 Linux)的一些输出:
$ dig pascal-martin.fr
; <<>> DiG 9.5.1-P2 <<>> pascal-martin.fr
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22164
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;pascal-martin.fr. IN A
;; ANSWER SECTION:
pascal-martin.fr. 86400 IN A 213.186.33.2
;; Query time: 29 msec
;; SERVER: 212.27.40.241#53(212.27.40.241)
;; WHEN: Fri Aug 7 00:00:47 2009
;; MSG SIZE rcvd: 50
Run Code Online (Sandbox Code Playgroud)
和 :
$ dig test.com
; <<>> DiG 9.5.1-P2 <<>> test.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62572
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;test.com. IN A
;; ANSWER SECTION:
test.com. 7200 IN A 204.12.0.50
;; Query time: 136 msec
;; SERVER: 212.27.40.241#53(212.27.40.241)
;; WHEN: Fri Aug 7 00:00:51 2009
;; MSG SIZE rcvd: 42
Run Code Online (Sandbox Code Playgroud)
似乎几乎相同...所以这里不是问题?
让我们尝试另一种:
$ host pascal-martin.fr
pascal-martin.fr has address 213.186.33.2
pascal-martin.fr mail is handled by 100 mxb.ovh.net.
pascal-martin.fr mail is handled by 1 mx0.ovh.net.
Run Code Online (Sandbox Code Playgroud)
和 :
$ host test.com
test.com has address 204.12.0.50
Run Code Online (Sandbox Code Playgroud)
嗯,这里有一个区别!问题可能是由 test.com 解析为 IP 但没有 MX 条目引起的吗?或者类似的东西?
也许是这样:当我用来dns_get_record测试 MX DNS 条目时,我没有 test.com 的结果:
array(0) {
}
Run Code Online (Sandbox Code Playgroud)
但我有两个 pascal-martin.fr :
array(2) {
[0]=>
array(6) {
["host"]=>
string(16) "pascal-martin.fr"
["type"]=>
string(2) "MX"
["pri"]=>
int(100)
["target"]=>
string(11) "mxb.ovh.net"
["class"]=>
string(2) "IN"
["ttl"]=>
int(14481)
}
[1]=>
array(6) {
["host"]=>
string(16) "pascal-martin.fr"
["type"]=>
string(2) "MX"
["pri"]=>
int(1)
["target"]=>
string(11) "mx0.ovh.net"
["class"]=>
string(2) "IN"
["ttl"]=>
int(14481)
}
}
Run Code Online (Sandbox Code Playgroud)
好吧,我真的不知道“为什么”......但至少这里有一些提示......
我在 php 文档中找不到其他任何内容;所以,我不知道这是否是有意的行为:-(
不管怎样:祝你好运!
编辑:嗯,在 Windows 下可能确实存在某种问题,因为当我尝试使用 Linux 时,我得到:
对于 test.com :
$ php temp.php
Type = A : bool(true)
Type = MX : bool(false)
Type = NS : bool(true)
Type = SOA : bool(true)
Type = PTR : bool(false)
Type = CNAME : bool(false)
Type = AAAA : bool(false)
Type = A6 : bool(false)
Type = SRV : bool(false)
Type = NAPTR : bool(false)
Type = TXT : bool(false)
Type = ANY : bool(true)
Run Code Online (Sandbox Code Playgroud)
并且,对于 pascal-martin.fr :
$ php temp.php
Type = A : bool(true)
Type = MX : bool(true)
Type = NS : bool(true)
Type = SOA : bool(true)
Type = PTR : bool(false)
Type = CNAME : bool(false)
Type = AAAA : bool(false)
Type = A6 : bool(false)
Type = SRV : bool(false)
Type = NAPTR : bool(false)
Type = TXT : bool(false)
Type = ANY : bool(true)
Run Code Online (Sandbox Code Playgroud)
所以,我在 Windows 上得到的不是同一件事(总是正确或总是错误) ......
也许有类似的情况,在 Windows 上,该函数总是寻找 MX 条目,而不考虑第二个参数?
(只是一个非常疯狂的猜测^^)