Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Api for Domains (PHP)

Posted on 2009-05-15
9
Medium Priority
?
552 Views
Last Modified: 2013-11-10
Hi E's, who known a really free api for check domains (php)?

Regards, JC
0
Comment
Question by:Pedro Chagas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 3

Expert Comment

by:markh789
ID: 24400777
You can make a script to check "http://who.is/whois/somedomain.com/" for the domain, and if it has "somedomain.com appears to be available". Check snippet.

I looked on php.net for fsock stuff, take a look.
<?php
// whois.php
if(isset($_GET['domainname'])) {
$fp = fsockopen("http://who.is/whois/" . $_GET['somedomain'] . "/", 80, $errno, $errstr, 30);
if (!$fp) {
    echo $errstr" . " (" . $errno . ")<br />\n";
} else {
    $out = "GET / HTTP/1.1\r\n";
    $out .= "Host: www.who.is\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        $data_string = $data_string . fgets($fp, 128);
    }
    fclose($fp);
 
    if(strstr($_GET['domainname'] . " appears to be available", $data_string)) {
         return true;
    } else {
         return false;
    }
}
}
?>

Open in new window

0
 
LVL 3

Expert Comment

by:markh789
ID: 24400780
Sorry, try new attached.
<?php
// whois.php
if(isset($_GET['domainname'])) {
$fp = fsockopen("http://who.is/whois/" . $_GET['somedomain'] . "/", 80, $errno, $errstr, 30);
if (!$fp) {
    echo $errstr . " (" . $errno . ")<br />\n";
} else {
    $out = "GET / HTTP/1.1\r\n";
    $out .= "Host: www.who.is\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        $data_string = $data_string . fgets($fp, 128);
    }
    fclose($fp);
 
    if(strstr($_GET['domainname'] . " appears to be available", $data_string)) {
         return true;
    } else {
         return false;
    }
}
}
?>

Open in new window

0
 
LVL 3

Expert Comment

by:markh789
ID: 24400806
This code would be smaller and would be a better method and seems it would be easier to put in,
<?php
function CheckDomain($domainname) {
if(strpos(file_get_contents(http://who.is/whois/' . $domainname), $domainname . ' appears to be available')!== false) {
return true;
} else {
return false;
}
}
 
if(CheckDomain("example.com")) {
 echo "Yes!";
} else {
 echo "No.";
}
 
?>

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:Pedro Chagas
ID: 24401936
Hi @markh789, your last code show this error:
Parse error: syntax error, unexpected ':' in /home/tags/public_html/teste2.php on line 3
//line 3 is: if(strpos(file_get_contents(http://who.is/whois/' . $domainname), $domainname . ' appears to be available')!== false) {

What is wrong is your last code?

Regards, JC
0
 
LVL 4

Accepted Solution

by:
manavsi earned 1000 total points
ID: 24402179
correct the above error as following snippet...
<?
function CheckDomain($domainname) {
if(strpos(file_get_contents('http://who.is/whois/' . $domainname), $domainname . ' appears to be available')!== false) {
return true;
} else {
return false;
}
}
 
if(CheckDomain("google.com")) {
 echo "Yes!";
} else {
 echo "No.";
}
 
?>

Open in new window

0
 
LVL 4

Expert Comment

by:manavsi
ID: 24402192
but look, when i try the above code.. i get NO for google.com
May be i would recommend you for this file here: Its the Best API i know...

Link: http://www.4shared.com/file/105722518/4d614b3f/enom-2007-04-24tar.html

Chk out the examples too...

HTH
Manavsi
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 total points
ID: 24403981
Try this... You may not need an API
<?php // RAY_checkdns.php
error_reporting(E_ALL);
 
// FUNCTION TO CHECK FOR A ROUTABLE DNS
function rout($url)
{
 
// PLUCK OUT THE TLD AND THE DOMAIN
   $x = explode('.', strtolower($url));
   if (!is_array($x)) // MAYBE 'localhost'?
   {
      return FALSE;
   }
 
// SOMETHING LIKE 'http://www.google.com' OR 'www2.atf70.whitehouse.gov'?
   else
   {
      $y   = count($x);
      $dmn = $x[$y-2] . '.' . $x[$y-1];
   }
 
// SEE IF THE DOMAIN.TLD IS ROUTABLE
   if ( checkdnsrr($dmn,"MX") || checkdnsrr($dmn,"A") ) return TRUE;
 
// IF NOT ROUTABLE
   return FALSE;
}
 
// TEST CASES
echo "<br/>Google.com ";
var_dump( rout('Google.com') );
 
echo "<br/>shmedlapp.net ";
var_dump( rout('shmedlapp.net') );

Open in new window

0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 24405742
Hi @ray, in your example, in //TEST CASES, if I want do:
//TEST CASES
rout('Google.com');
if (available){
 echo "available";
} else {
echo "not available";
}

Sorry the question, but I don't understand well about "return".
==================================================
For @manavsi, I think your last script work well, for google.com the answer is NO, off course NO because is not available! If I try the domain: "sdgfdshfdhdf.com" the answer is YES, because is available!
So I thing your script work well. Thanks for that.

Regards, JC
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 24406532
OK, please tell me a little bit more.  Am I understanding it correctly?  You want to know if a domain is registered or available?

I think this is how I would use that code that I posted earlier (see snippet).

Either function may work well for you, but the built-in PHP function checkdnsrr() does not make your programming dependent on an external service.
if (!rout('Google.com'){ echo "available"; }

Open in new window

0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Starting your own business is always a daunting process, and for most people it is brand new experience. Avoid the common pitfalls by following these tips to start on the road to success.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question