PHP domain age checker script

I was looking for php domain age checker script so I googled for it, but didn’t found any useful code. So I decided to write my own. It may be useful for webmasters. This script is based on our previous php whois script which extracts whois information from whois server.

class DomainAge{
  private $WHOIS_SERVERS=array(
  "com"               =>  array("","/Creation Date:(.*)/"),
  "net"               =>  array("","/Creation Date:(.*)/"),
  "org"               =>  array("","/Created On:(.*)/"),
  "info"              =>  array("","/Created On:(.*)/"),
  "biz"               =>  array("","/Domain Registration Date:(.*)/"),
  "us"                =>  array("","/Domain Registration Date:(.*)/"),
  "uk"                =>  array("","/Registered on:(.*)/"),
  "ca"                =>  array("","/Creation date:(.*)/"),
  "tel"               =>  array("","/Domain Registration Date:(.*)/"),
  "ie"                =>  array("","/registration:(.*)/"),
  "it"                =>  array("","/Created:(.*)/"),
  "cc"                =>  array("","/Creation Date:(.*)/"),
  "ws"                =>  array("","/Domain Created:(.*)/"),
  "sc"                =>  array("","/Created On:(.*)/"),
  "mobi"              =>  array("","/Created On:(.*)/"),
  "pro"               =>  array("","/Created On:(.*)/"),
  "edu"               =>  array("","/Domain record activated:(.*)/"),
  "tv"                =>  array("","/Creation Date:(.*)/"),
  "travel"            =>  array("","/Domain Registration Date:(.*)/"),
  "in"                =>  array("","/Created On:(.*)/"),
  "me"                =>  array("","/Domain Create Date:(.*)/"),
  "cn"                =>  array("","/Registration Date:(.*)/"),
  "asia"              =>  array("","/Domain Create Date:(.*)/"),
  "ro"                =>  array("","/Registered On:(.*)/"),
  "aero"              =>  array("","/Created On:(.*)/"),
  "nu"                =>  array("","/created:(.*)/")
  public function age($domain)
  $domain = trim($domain); //remove space from start and end of domain
  if(substr(strtolower($domain), 0, 7) == "http://") $domain = substr($domain, 7); // remove http:// if included
  if(substr(strtolower($domain), 0, 4) == "www.") $domain = substr($domain, 4);//remove www from domain
  $domain_parts = explode(".", $domain);
  $tld = strtolower(array_pop($domain_parts));
  if(!$server=$this->WHOIS_SERVERS[$tld][0]) {
  return false;
  $time = time() - strtotime($match[1]);
  $years = floor($time / 31556926);
  $days = floor(($time % 31556926) / 86400);
  if($years == "1") {$y= "1 year";}
  else {$y = $years . " years";}
  if($days == "1") {$d = "1 day";}
  else {$d = $days . " days";}
  return "$y, $d";
  return false;
  return false;
  private function queryWhois($server,$domain)
  $fp = @fsockopen($server, 43, $errno, $errstr, 20) or die("Socket Error " . $errno . " - " . $errstr);
  fputs($fp, $domain . "rn");
  $out = "";
  $out .= fgets($fp);
  return $out;

How this script works?

This script has array of whois server along with regular expression pattern for domain registration date because each TLD has different whois server and different whois result format. First it extracts whois information from whois server same as in our previous php whois script. Then it extracts domain registration date from whois result using regular expression. In next step it converts domain registration date into UNIX timestamp using php strtotime function. Finally it subtracts domain registration timestamp from current timestamp to get domain age in seconds.

How To Use It?

Save above class as DomainAge.class.php and use following code

$w=new DomainAge();
echo $w->age("");

Published by Sunny

A Mechanical engineer by education and web developer by passion and profession. He lives in Lucknow, India. Currently earning his livings by hitting keyboad. ;)

Join the Conversation


Leave a comment

Your email address will not be published. Required fields are marked *