【问题标题】:php domain availability function [duplicate]php域可用性功能[重复]
【发布时间】:2009-08-03 02:35:48
【问题描述】:

我找不到可以检查域是否可用的有效 php 域可用性函数,然后定义一个可用或不可用的 $status 变量,因此我可以将其包含在我的消息中。

关于如何做到这一点的任何提示?我尝试了各种原生 php 函数,如 getdnsrr 和其他函数,但无法让它们工作。我只需要将 $status 定义为可用或不可用。

感谢您的帮助。

【问题讨论】:

  • “可用”是什么意思?您的意思是域指向的机器已启动并正在运行,因此可用于请求?你的意思是“没有人注册这个域所以它可以购买”吗?还有什么?

标签: php


【解决方案1】:

谷歌搜索结果

<?php
// Function to check response time
function pingDomain($domain){
    $starttime = microtime(true);
    $file      = fsockopen ($domain, 80, $errno, $errstr, 10);
    $stoptime  = microtime(true);
    $status    = 0;

    if (!$file) $status = -1;  // Site is down
    else {
        fclose($file);
        $status = ($stoptime - $starttime) * 1000;
        $status = floor($status);
    }
    return $status;
}
?>

返回 ping 服务器所用的时间。
http://www.tutcity.com/view/check-your-server-status-a-basic-ping.10248.html


检查域是否可用:

 <?php
    function checkDomain($domain,$server,$findText){
        // Open a socket connection to the whois server
        $con = fsockopen($server, 43);
        if (!$con) return false;

        // Send the requested doman name
        fputs($con, $domain."\r\n");

        // Read and store the server response
        $response = ' :';
        while(!feof($con)) {
            $response .= fgets($con,128); 
        }

        // Close the connection
        fclose($con);

        // Check the response stream whether the domain is available
        if (strpos($response, $findText)){
            return true;
        }
        else {
            return false;   
        }
    }
?>

$status = checkDomain("stackoverflow.com",'whois.crsnic.net','No match for');

【讨论】:

  • 好提示,但我需要确定该域是否已注册
  • 您赢得了 20,000 个互联网。我希望 SO 上有一个拥抱按钮,因为我现在正在按下它。非常感谢。
猜你喜欢
  • 1970-01-01
  • 2011-07-17
  • 2011-12-20
  • 1970-01-01
  • 2013-09-22
  • 2016-03-20
  • 2018-12-18
  • 2015-06-29
  • 1970-01-01
相关资源
最近更新 更多