Check if a domain name is registered?

Discussion in 'PHP' started by Hecky, Sep 7, 2010.

  1. #1
    Hey,

    Trying to find the solution to how I could check whether a domain was registered using PHP, I came across this code :

    function checkDomainReg($domain, $server="whois.crsnic.net") { 
    /*	Author: David Wade Arnold -- david@eccentrichosting.net
    	checkDomainReg: checks to see if a domain name is taken. Returns boolean false 
    	domain name is not taken.
    	configuration: This scripts depends on one line of a whois output. 
    	If the whois server is changed make sure that the lineNumber variable
    	is changed to the line that returns:
    	   Domain Name: ECCENTRICTECHNOLOGIES.COM
    	-- when domain exists
    	and
    	No match for "ASHDFIOWUET.NET".
    	-- when domain does not exist 
    	This line is diffrent for diffrent whois servers. 
    	wrap-up: Please email me if you make changes. Hey, I want a better version too!
    */
    	$lineNumber = 8;
    	// open a socket connection to a whois server
    	$fp = fsockopen ($server, 43, &$errnr, &$errstr) or die("$errno: $errstr");
    	fputs($fp, "$domain\n");
    	while (!feof($fp)) {
    		//return each line of stout and place it in $serverReturn
    		$serverReturn = fgets($fp, 2048);
    		$x++;
    		if ($x == $lineNumber) { 
    			$line = $serverReturn;
    		}
    	}
    	fclose($fp);
    	//tokenize the string so we can find the No
    	$token = strtok("$line"," ");
    	if ($token == 'No') {
    		$result = 0;
    	} else {
    		$result = 1;
    	}
    	return $result; 
    } 
    
    
    
     ?>
    <?
    If (isset ($domain)){
    	$answer = checkDomainReg($domain);
    	if($answer) {
    		echo "Please try again the domain $domain is registered";
    	} else {
    		echo "$domain Is free to register"; }
    }
    ?>
    
    Code (markup):
    Source : http://webscripts.softpedia.com/scriptDownload/Check-if-Domain-is-Registration-Download-10172.html

    And I was thinking about whether this would be practical to do possibly thousands of times each day because it calls upon a 3rd party whois server, will they allow me to?

    Thanks
     
    Hecky, Sep 7, 2010 IP
    Mightee likes this.
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    danx10, Sep 7, 2010 IP
  3. Hecky

    Hecky Like a Dungeon Dragon!

    Messages:
    5,656
    Likes Received:
    284
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Thanks, but I'm just looking into it and it seems like it doesn't work on a windows operating system?
     
    Hecky, Sep 7, 2010 IP