Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this is the servers array that I keep top level domain names and extensions

 protected $servers = array(
        
        "com.tr" => "whois.nic.tr",
        "gen.tr" => "whois.nic.tr",
        "web.tr" => "whois.nic.tr",
        "k12.tr" => "whois.nic.tr",
        "org.tr" => "whois.nic.tr"
    );


What I have tried:

I am required to get whois info so I wrote this function


    function whois($domain,$ext)
    {
               $server=$this->servers[$ext];
               $domain=$domain.".".$ext;
             
        if (function_exists('curl_version')) {
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $server);
            curl_setopt($curl, CURLOPT_PORT, 43);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_TIMEOUT, 5);
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $domain."\r\n");
            $result = curl_exec($curl);
            curl_close($curl);

                    
                    echo print_r($result);
                   
        } else {
            trigger_error('cURL is not found!');
            exit();
        }




    }

I  am using this way
whois("google","com");

This function works  for google.com and It gives me the correct domain information But when I execute  for google.org.tr then (this is the intersting part)  sometimes retuns 

    
    No match found for "google.org.tr"(whis is expected)
 
     and  somethimes return "1"
Posted
Updated 10-Apr-19 6:18am

1 solution

The reason you are getting 1 is because of the following line:

PHP
echo print_r($result);


You see, how you are using `echo` and `print_r`, so in this case `print_r` is returning `true` which is being typecasted into integer and is being printed as `1` by `echo`.
So, just remove that and it should be fine.
 
Share this answer
 
Comments
Member 3722539 10-Apr-19 13:01pm    
how can I display the content
[no name] 10-Apr-19 13:21pm    
print_r should be enough for that

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900