检查域是否可用或未使用 PHP?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8693490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 05:17:27  来源:igfitidea点击:

check to see if a domain is available or not using PHP?

php

提问by David19801

If I have a domain like www.example.comand 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 来做到这一点?

回答by favo

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:

示例获取主机名:

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

回答by Matthew Kolb

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

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

回答by Christian Neverdal

Certainly. Thisis what happens for an available domain.

当然就是可用域发生的情况。

回答by 0x1ad2

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

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

回答by Zefir Zdravkov

All answers suggest using some PHP library. There's a function in vanillaPHP (version 5 to 7) that fetches DNS records for a specific domain.

所有答案都建议使用一些 PHP 库。vanillaPHP(版本 5 到 7)中有一个函数可以获取特定域的 DNS 记录。

Utilising the following PHPline,

使用以下PHP行,

sizeof(dns_get_record("example.com"))

you will get an INT corresponding to the number of DNS records. Therefore, consider something alike:

您将获得与 DNS 记录数量相对应的 INT。因此,请考虑类似的事情:

if (sizeof(dns_get_record("example.com")) > 0) echo "Domain has DNS records";
else echo "Domain does not have any DNS records";

Documentation

文档