Getting Information About a Domain Name with PHP
When looking at a domain name as part of an email address or URL, you simply do not get enough information from it. You can even go so far as visiting that URL and you still will not have enough information about the ownership of that particular domain. Most of the kind of information that you would want will be located in a WHOIS database. These databases are maintained by registrars and can provide information about the owners of a particular domain. To get the information from these databases, you need to run a
whoisquery from a client application. PHP provides this kind of client application through the PEAR package.
PEAR has a class called Net_Whois that enables you to query a whois database. You use it like so:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <? require_once "Net/Whois.php"; $server = "whois.networksolutions.com"; $query = "metroworks.com"; $whois = new Net_Whois; $urlinfo = $whois->query($query, $server); var_dump($urlinfo); ?> </body> </html>
First, the code defines the server where the whois database is located:
$server = "whois.networksolutions.com";
Then it defines the name of the domain that it wants to run a query on:
$query = "metroworks.com";
Finally, the query is run, after the Net_whois class is instantiated:
$whois = new Net_Whois; $urlinfo = $whois->query($query, $server);
And the information from the query is shown:
var_dump()function will show the entire contents of the
Download the Code