使用PHP检查域是否可用?

时间:2022-09-21 16:53:17

If I have a domain like www.example.com and I want to check if it is available using DNS records (not whois)...

如果我有一个像www.example.com这样的域名,我想检查它是否可以使用DNS记录(而不是whois)...

Is it possible to do this using PHP?

是否可以使用PHP执行此操作?

6 个解决方案

#1


30  

You can use checkdnsrr or gethostbyname:

您可以使用checkdnsrr或gethostbyname:

Documentation:

文档:

http://www.php.net/checkdnsrr

http://www.php.net/checkdnsrr

http://www.php.net/gethostbyname

http://www.php.net/gethostbyname

Example checkdnsrr:

示例checkdnsrr:

<?php
 if ( checkdnsrr('example.com.', 'ANY') ) {
  echo "DNS Record found";
 }
 else {
  echo "NO DNS Record found";
 }
?>

Example gethostbyname:

示例gethostbyname:

<?php
 $domain = 'example.com';
 if ( gethostbyname($domain) != $domain ) {
  echo "DNS Record found";
 }
 else {
  echo "NO DNS Record found";
 }
?>

#2


2  

it seems it is in standard php library, check this function http://php.net/manual/en/function.dns-get-record.php

它似乎是在标准的php库中,检查这个函数http://php.net/manual/en/function.dns-get-record.php

#3


2  

It depends on what you mean by "available." If you mean available for registration, it is not possible to determine based on DNS information alone. The whois system must be used. An easy way to test is to take an unused domain name and set the nameservers to something invalid. DNS will not be available, but the domain is still unavailable for registration. I just tested the suggestions of checkdnsrr(), gethostbyname(), and dns_get_record(). All show that no DNS is returned for a domain that cannot be registered.

这取决于“可用”的含义。如果您的意思是可以注册,则无法单独根据DNS信息确定。必须使用whois系统。一种简单的测试方法是获取一个未使用的域名,并将名称服务器设置为无效的名称。 DNS将不可用,但该域仍无法注册。我刚刚测试了checkdnsrr(),gethostbyname()和dns_get_record()的建议。全部显示没有为无法注册的域返回DNS。

The following question offers some more details: Checking if a domain name is registered

以下问题提供了一些更多详细信息:检查域名是否已注册

#4


1  

Certainly. This is what happens for an available domain.

当然。这是可用域的情况。

#5


0  

Some of the API that will do the job.

一些将完成这项工作的API。

http://www.whoisxmlapi.com/domain-availability.php

http://www.whoisxmlapi.com/domain-availability.php

http://www.dynadot.com/domain/api.html

http://www.dynadot.com/domain/api.html

http://www.opensrs.com/site/integration/api

http://www.opensrs.com/site/integration/api

#6


0  

I should go for this package Domain-Availability it's support a lot of Top Level Domains and is written in a Object Oriented way.

我应该选择这个包Domain-Availability,它支持很多*域名,并以面向对象的方式编写。

#1


30  

You can use checkdnsrr or gethostbyname:

您可以使用checkdnsrr或gethostbyname:

Documentation:

文档:

http://www.php.net/checkdnsrr

http://www.php.net/checkdnsrr

http://www.php.net/gethostbyname

http://www.php.net/gethostbyname

Example checkdnsrr:

示例checkdnsrr:

<?php
 if ( checkdnsrr('example.com.', 'ANY') ) {
  echo "DNS Record found";
 }
 else {
  echo "NO DNS Record found";
 }
?>

Example gethostbyname:

示例gethostbyname:

<?php
 $domain = 'example.com';
 if ( gethostbyname($domain) != $domain ) {
  echo "DNS Record found";
 }
 else {
  echo "NO DNS Record found";
 }
?>

#2


2  

it seems it is in standard php library, check this function http://php.net/manual/en/function.dns-get-record.php

它似乎是在标准的php库中,检查这个函数http://php.net/manual/en/function.dns-get-record.php

#3


2  

It depends on what you mean by "available." If you mean available for registration, it is not possible to determine based on DNS information alone. The whois system must be used. An easy way to test is to take an unused domain name and set the nameservers to something invalid. DNS will not be available, but the domain is still unavailable for registration. I just tested the suggestions of checkdnsrr(), gethostbyname(), and dns_get_record(). All show that no DNS is returned for a domain that cannot be registered.

这取决于“可用”的含义。如果您的意思是可以注册,则无法单独根据DNS信息确定。必须使用whois系统。一种简单的测试方法是获取一个未使用的域名,并将名称服务器设置为无效的名称。 DNS将不可用,但该域仍无法注册。我刚刚测试了checkdnsrr(),gethostbyname()和dns_get_record()的建议。全部显示没有为无法注册的域返回DNS。

The following question offers some more details: Checking if a domain name is registered

以下问题提供了一些更多详细信息:检查域名是否已注册

#4


1  

Certainly. This is what happens for an available domain.

当然。这是可用域的情况。

#5


0  

Some of the API that will do the job.

一些将完成这项工作的API。

http://www.whoisxmlapi.com/domain-availability.php

http://www.whoisxmlapi.com/domain-availability.php

http://www.dynadot.com/domain/api.html

http://www.dynadot.com/domain/api.html

http://www.opensrs.com/site/integration/api

http://www.opensrs.com/site/integration/api

#6


0  

I should go for this package Domain-Availability it's support a lot of Top Level Domains and is written in a Object Oriented way.

我应该选择这个包Domain-Availability,它支持很多*域名,并以面向对象的方式编写。