Skip to content
Advertisement

domain registry api integrate in php

I want to integrate one API with one of my website which is a task given by my senior.The API is about searching domain name already present or not..please help me on this topic please give me n example which i can refer.my website is in PHP.

Advertisement

Answer

[EDIT 2] As @Poe mentions in his comment, gethostbyname is probably a much better solution because it works for any top level domain, since it performs a DNS query instead of a whois query, and is also much simpler to implement and probably faster:

<?php
$ip = gethostbyname('example.com');
if (strstr($ip,"example.com")){
    echo "No match for domain example.com<br />n";
} else {
    echo "Domain found. Query output: <br />n".$ip;
}
?>

Anyway, a domain can be registered but its not linked to any computer (E.g. although it’s very uncommon, you may get an resolution for www.example.com but not example.com)

[EDIT] I didn’t post this before because I was having some trouble connecting to whois.internic.net on port 43 to perform a whois query (thought they had shutdown the service for good). Anyway, here’s a fsockopen based solution I just coded, which I think is far better and simpler than the solution I gave before using their CGI web script. Hope it helps (Usage: myqueryscript.php?domain=domainiwanttocheck.com):

<?php
$fp = fsockopen("199.7.58.74", 43, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />n";
} else {
    $query = $_GET['domain']."rn";
    $answer= '';
    fwrite($fp, $query);
    while (!feof($fp)) {
        $answer .= fgets($fp, 128)."<br />";
    }
    fclose($fp);
    if (strstr($answer,"No match for")){
        echo "No match for domain ".$_GET['domain']."<br />n";
    } else {
        echo "Domain found. Query output: <br />n".$answer;
    }
}
?>

From internic website, this is the html code to implement a whois query:

<form method="get" action="http://reports.internic.net/cgi/whois" name="my_form">
            <input type="text" size="30" name="whois_nic" maxlength="80">
            <br>
            <input type="radio" name="type" value="domain" checked>
            Domain<font size="-1"> (ex. internic.net)
            <br>
            <input type="radio" name="type" value="registrar">
            Registrar<font size="-1"> (ex. ABC Registrar, Inc.) 
            <br>
            <input type="radio" name="type" value="nameserver">
            Nameserver (ex. NS.EXAMPLE.COM or 192.16.0.192)<br>
            <br>
            <input type="submit" value="Submit">
  </form>

This means you can send a whois query like this: http://reports.internic.net/cgi/whois?whois_nic=domainiwanttocheck.com&type=domain

You can send the query from your script and store the response on a DOMDocument object. Check out: http://www.php.net/manual/en/domdocument.loadhtml.php

If you use this method to lookup a domain and the domain doesn’t exist, you’ll get the string No match for domain. Look for this in the response using strpos

If the domain exists, you can filter the response to include the info about registrar, etc. It will be the content of the html tag <pre> of the response:

<pre>

Whois Server Version 2.0

Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.

   Domain Name: GOOGLE.COM
   Registrar: MARKMONITOR INC.
   Whois Server: whois.markmonitor.com
   Referral URL: http://www.markmonitor.com
   Name Server: NS1.GOOGLE.COM
   Name Server: NS2.GOOGLE.COM
   Name Server: NS3.GOOGLE.COM
   Name Server: NS4.GOOGLE.COM
   Status: clientDeleteProhibited
   Status: clientTransferProhibited
   Status: clientUpdateProhibited
   Status: serverDeleteProhibited
   Status: serverTransferProhibited
   Status: serverUpdateProhibited
   Updated Date: 20-jul-2011
   Creation Date: 15-sep-1997
   Expiration Date: 14-sep-2020

>>> Last update of whois database: Sat, 25 Aug 2012 10:15:09 UTC <<<

NOTICE: The expiration date displayed in this record is the date the 
registrar's sponsorship of the domain name registration in the registry is 
currently set to expire. This date does not necessarily reflect the expiration 
date of the domain name registrant's agreement with the sponsoring 
registrar.  Users may consult the sponsoring registrar's Whois database to 
view the registrar's reported date of expiration for this registration.

TERMS OF USE: You are not authorized to access or query our Whois 
database through the use of electronic processes that are high-volume and 
automated except as reasonably necessary to register domain names or 
modify existing registrations; the Data in VeriSign Global Registry 
Services' ("VeriSign") Whois database is provided by VeriSign for 
information purposes only, and to assist persons in obtaining information 
about or related to a domain name registration record. VeriSign does not 
guarantee its accuracy. By submitting a Whois query, you agree to abide 
by the following terms of use: You agree that you may use this Data only 
for lawful purposes and that under no circumstances will you use this Data 
to: (1) allow, enable, or otherwise support the transmission of mass 
unsolicited, commercial advertising or solicitations via e-mail, telephone, 
or facsimile; or (2) enable high volume, automated, electronic processes 
that apply to VeriSign (or its computer systems). The compilation, 
repackaging, dissemination or other use of this Data is expressly 
prohibited without the prior written consent of VeriSign. You agree not to 
use electronic processes that are automated and high-volume to access or 
query the Whois database except as reasonably necessary to register 
domain names or modify existing registrations. VeriSign reserves the right 
to restrict your access to the Whois database in its sole discretion to ensure 
operational stability.  VeriSign may restrict or terminate your access to the 
Whois database for failure to abide by these terms of use. VeriSign 
reserves the right to modify these terms at any time. 

The Registry database contains ONLY .COM, .NET, .EDU domains and
Registrars.
        </pre>

Also, check out this related question: Who provides a WHOIS API?

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement