php whois停止在另一台服务器上工作

时间:2016-01-31 18:51:04

标签: php apache whois

我正在使用这个whois类,它在一台服务器上工作正常,但它在另一台具有相同PHP版本5.4的服务器上无法正常工作,在第一台服务器上它正确返回域名状态,但在另一台服务器上它只返回一个状态:"域名不可用"而域名实际上是可用的。

<?
class Whois_domain {

    var $possible_tlds;
    var $whois_server;
    var $free_string;
    var $whois_param;
    var $domain;
    var $tld;
    var $compl_domain;
    var $full_info;
    var $msg;
    var $info;
    var $os_system = "linux"; // switch between "linux" and "win"

    function Whois_domain() {
        $this->info = "";
        $this->msg = "";
    }
    function process() {
        if ($this->create_domain()) {
            if ($this->full_info == "yes") {
                $this->get_domain_info();
            } else {
                if ($this->check_only() == 1) {
                    $this->msg = "The domain name: <b>".$this->compl_domain."</b> is free.";
                    return true;
                } elseif ($this->check_only() == 0) {
                    $this->msg = "The domain name: <b>".$this->compl_domain."</b> is not available";
                    return false;
                } else {
                    $this->msg = "There was something wrong, try it again.";
                }
            }
        } else {
            $this->msg = "Only letters, numbers and hyphens (-) are valid!";
        }
    }
    function check_entry() {
        if (preg_match("/^([a-z0-9]+(\-?[a-z0-9]*)){2,63}$/i", $this->domain)) {
            return true;
        } else {
            return false;
        }
    }
    function create_tld_select() {
        $menu = "<select name=\"tld\" style=\"margin-left:0;\">\n";
        foreach ($this->possible_tlds as $val) {
            $menu .= "  <option value=\"".$val."\"";
            $menu .= (isset($_POST['tld']) && $_POST['tld'] == $val) ? " selected=\"selected\">" : ">";
            $menu .= $val."</option>\n";
        }
        $menu .= "</select>\n";
        return $menu;
    }
    function create_domain() {
        if ($this->check_entry()) {
            $this->domain = strtolower($this->domain);
            $this->compl_domain = $this->domain.".".$this->tld;
            return true;
        } else {
            return false;
        }
    }
    function check_only() {
        $data = $this->get_whois_data();
        if (is_array($data)) {
            $found = 0;
            foreach ($data as $val) {
                if (eregi($this->free_string, $val)) {
                    $found = 1;
                } 
            }
            return $found;
        } else {
            $this->msg = "Error, please try it again.";
        }
    }
    function get_domain_info() {
        if ($this->create_domain()) {
            $data = ($this->tld == "nl") ? $this->get_whois_data(true) : $this->get_whois_data();
            if (is_array($data)) {
                foreach ($data as $val) {
                    if (eregi($this->free_string, $val)) {
                        $this->msg = "The domain name: <b>".$this->compl_domain."</b> is free.";
                        $this->info = "";
                        break;
                    }
                    $this->info .= $val;
                }
            } else {
                $this->msg = "Error, please try it again.";
            }
        } else {
            $this->msg = "Only letters, numbers and hyphens (-) are valid!";
        }
    }
    function get_whois_data($empty_param = false) { 
    // the parameter is new since version 1.20 and is used for .nl (dutch) domains only
        if ($empty_param) {
            $this->whois_param = "";
        }
        if ($this->tld == "de") $this->os_system = "win"; // this tld must be queried with fsock otherwise it will not work
        if ($this->os_system == "win") {
            $connection = @fsockopen($this->whois_server, 43);
            if (!$connection) {
                unset($connection);
                $this->msg = "Can't connect to the server!";
                return;
            } else {
                sleep(2);
                fputs($connection, $this->whois_param.$this->compl_domain."\r\n");
                while (!feof($connection)) {
                    $buffer[] = fgets($connection, 4096);
                }
                fclose($connection);
            }
        } else {
            $string = "whois -h ".$this->whois_server." \"".$this->whois_param.$this->compl_domain."\""; 
            $string = str_replace (";", "", $string).";";
            exec($string, $buffer);
        }
        if (isset($buffer)) {
            //print_r($buffer);
            return $buffer;
        } else {
            $this->msg = "Can't retrieve data from the server!";
        }
    }
}
?>

我在其他服务器上更改了文件权限和php版本,但仍然相同。

1 个答案:

答案 0 :(得分:0)

这已经解决了,服务器上有 fsockopen 限制,现在很好。