PHP Domain Checking

Discussion in 'PHP' started by tndrloin, Sep 29, 2007.

  1. #1
    I'm getting my feet wet in PHP. I tried to check the first 10 pages of the PHP forum but couldn't find the answer to the following question:

    How do you test if a domain is already taken or still available by way of PHP programming?

    Sorry if the question has already been answered previously.
     
    tndrloin, Sep 29, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    nico_swd, Sep 29, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    Because I thought it was interesting.
    
    function domain_is_taken($domain)
    {
    	static $whois;
    	
    	if (!isset($whois))
    	{
    		include 'phpwhois-4.1.2/whois.main.php';
    		$whois = new Whois();
    	}
    	
    	$response = $whois->lookup($domain);
    	return !empty($response['regyinfo']['registrar']);
    }
    
    
    PHP:

    Usage example:
    
    $domains = array('php.net', 'nicoswd.com', 'efwfffwer.com', 'yahahahs.com');
    
    foreach ($domains AS $domain)
    {
    	echo "{$domain} is ", domain_is_taken($domain) ? 'Taken' : 'Available', "<br />\n";
    }
    
    PHP:

    You have to download this class though, and set the path to it right in the function.

    http://sourceforge.net/projects/phpwhois/
     
    nico_swd, Sep 29, 2007 IP
  4. Andrei P.

    Andrei P. Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you don't want to use the class pointed above, check this: http://www.geekpedia.com/code15_WhoIs-function-for-domain-name-info.html

    I posted that a few days ago. I used it to retrieve and parse the name of the domain-name owner, but you could as well use it to see if the domain-name is registered or not, depending on the response retrieved.
     
    Andrei P., Sep 29, 2007 IP