php 域名可用性函数

标签 php

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

关于如何执行此操作有任何提示吗?我尝试过各种 native php 函数,如 getdnsrr 等,但无法让它们工作。我只需要将 $status 定义为可用或不可用。

感谢您的帮助。

最佳答案

谷歌结果

<?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');

关于php 域名可用性函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1220484/

相关文章:

php - 如果用户名不在日志中设置为脱机

php - laravel 中的“无法创建目录”错误(在服务器上)

php - 阻止人们入侵 Flash 游戏的基于 PHP 的高分表的最佳方法是什么?

php - 使用 fopen、mysql 查询、include/require 检索字符串值的速度如何

php - MySQL : Order by and Group By combining not giving the latest record

php - 从 id_numbers 列但从多行获取唯一的 ID 号 MySQL

php - 从带有缩略图或介绍图片的 wordpress 数据库中选择帖子

php - Joomla:JDatabase 与 PHP 的直接 SQL 操作

javascript - wc_countries - 状态选择下拉列表 - woocommerce

php - 登录页面不工作