PHP - Domain Tools Class

5 replies
PHP - Domain Tools Class

This is a domain class I wrote today which has the functions of:
GetRegistrar
GetWhoisServer
GetUpdatedDate
GetCreationDate
GetExpirationDate
It's easy to read, learn, and use.

I used file_get_contents rather than curl as curl is not enabled on all hosts, but a majority of them and plus I would of only used curl if I had wanted to increase speed, and flexibility.



PHP Source:
Code:
<?php
/**
* @author Vick@CoderzSpot.com
* @website www.CoderzSpot.com
* @version 1.0
* @date(25-10-2011)
* @contact vick@hotmail.com.au
**/
class Domain{
    function GetRegistrar($url)
    {
        $output = file_get_contents("http://new.whois.net/whois/$url");
        $regex = '/Registrar: (.+?) Whois/';
        preg_match($regex, $output, $match);
        echo "Registrar: ".$match[1];
    }
   
    function GetWhoisServer($url)
    {
        $output = file_get_contents("http://new.whois.net/whois/$url");
        $regex = '/Whois Server: (.+?) Referral/';
        preg_match($regex, $output, $match);
        echo "Whois Server: ".$match[1];       
    }
   
    function GetUpdatedDate($url)
    {
        $output = file_get_contents("http://new.whois.net/whois/$url");
        $regex = '/Updated Date: (.+?) Creation/';
        preg_match($regex, $output, $match);
        echo "Updated Date: ".$match[1];         
    }
   
    function GetCreationDate($url)
    {
        $output = file_get_contents("http://new.whois.net/whois/$url");
        $regex = '/Creation Date: (.+?) Expiration/';
        preg_match($regex, $output, $match);
        echo "Creation Date: ".$match[1];         
    }
   
    function GetExpirationDate($url)
    {
        $output = file_get_contents("http://new.whois.net/whois/$url");
        $regex = '/Expiration Date: (.+?) /';
        preg_match($regex, $output, $match);
        $substr = substr($match[1], 0, -11);
        echo "Expiration Date: ".$substr;         
    }   
}
$domain = new Domain();
$domain->GetRegistrar("coderzspot.com");
$domain->GetWhoisServer("coderzspot.com");
$domain->GetUpdatedDate("coderzspot.com");
$domain->GetCreationDate("coderzspot.com");
$domain->GetExpirationDate("coderzspot.com");
?>
Original Thread, and for updates -> http://www.coderzspot.com/index.php?...n-tools-class/
#class #domain #php #tools
  • Profile picture of the author Tim Brownlaw
    G'day Vick

    I've had a bit of a play with your class and would make the following suggestions.

    1. In each method you run off to the site to extract the data... As you are calling most of the methods and as most of these services don't take kindly to being visited from the same IP a whole lot and also as it's not neccessary.... you should create a private var called output and send the URL in the constructor and have each method refer to it - ie $this->output

    This would mean that you would need to instantiate a class for each URL you want to find out about, but that's no biggy and makes more sense,

    2. I noticed that the info coming back for your URL (in the sample code) is different to what is retrieved for some of my sites, meaning that your regex breaks in some cases.
    Seems there are at least two different sets of info that can come back....
    ie public vs private.

    I added a debug method so I can turn on and off a print_r for the returned regex ( as I was playing with it...) and I also added a display method to show the retrieved output obtained when the constructor is called... It's a lil messed up at the moment and I've got other things to get done!

    So there is "some stuff" to consider. Just thought I'd throw that in for you to do what you like with it.

    I also joined your Forum and I've not put my hand up in there yet....until I get some free time.

    Cheers
    Tim
    {{ DiscussionBoard.errors[4955007].message }}
  • Profile picture of the author mmstud
    Thats great idea for PHP SEO tool arsenal I've been collecting and creating. Sorry I had longer post here but WF showed database error and I lost the content *Grrr*
    {{ DiscussionBoard.errors[4955460].message }}
  • Profile picture of the author pfreelancer
    This looks good for web hosting resellers as well.
    {{ DiscussionBoard.errors[4965478].message }}
  • Profile picture of the author wasabi20
    Great classes !

    Keep good works
    {{ DiscussionBoard.errors[5025791].message }}
    • Profile picture of the author megazord100
      Thanks for the class. Very nice.
      {{ DiscussionBoard.errors[5037719].message }}

Trending Topics