0

I am using this whois class, it works fine on one server but it does not work properly on another server with the same PHP version 5.4, on first server it returns domain name status correctly, but on the other one it returns just one status: "domain name is not available" while the domain name is actually available.

<?
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!";
        }
    }
}
?>

I changed files permissions and php versions on the other server, but still the same.

Basheer
  • 328
  • 1
  • 2
  • 10
  • 3
    Can you clarify "does not work"? Are you getting an error message? What is the expected behavior and how does the actual behavior differ from that? – Mathew Tinsley Jan 31 '16 at 18:53
  • @mtinsley thanks for your reply, the script works fine on first server, it returns domain name status correctly, but on the other one, it returns just one status: "domain name is not available" while the domain name is actually available, this is the issue. – Basheer Jan 31 '16 at 18:58
  • 1
    You should update the question with any additional information rather than just adding it to the comments. One thing I'm noticing in your code is that you are constantly overwriting `$this->msg`. You only get the last error which is most likely the most generic error message. Update your code to log or output every error instead of just the last and you will be more likely to find the point of failure. – Mathew Tinsley Jan 31 '16 at 19:04
  • @mtinsley no errors are generated, log file does not exist. – Basheer Jan 31 '16 at 19:12
  • 1
    The log file doesn't exist *yet*. You'll have to create it. Lookup `error_log`. – Mathew Tinsley Jan 31 '16 at 19:14
  • @mtinsley error_log created, it got test errors I done in test file, but it does not generate any errors from whois script. – Basheer Jan 31 '16 at 19:21
  • 1
    Instead of (or in addition to) `$this->msg = 'Some error message';`, call `error_log('Some error message');`. Once you do that your error log will contain every message rather than just the last one. – Mathew Tinsley Jan 31 '16 at 19:26
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/102169/discussion-between-basheer-h-and-mtinsley). – Basheer Jan 31 '16 at 19:32

1 Answers1

0

This has been solved, it was fsockopen restrictions on the server, it is fine now.

Basheer
  • 328
  • 1
  • 2
  • 10