PHP
  Home arrow PHP arrow Page 5 - Using PHP classes to navigate distribu...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Using PHP classes to navigate distributed whois databases
By: Mark Jeftovic
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    1999-12-07

    Table of Contents:
  • Using PHP classes to navigate distributed whois databases
  • Overview of the whois landscape
  • Making sense of it with PHP classes
  • Overview of Whois2.php
  • Looking at the pieces
  • Tying it all together
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using PHP classes to navigate distributed whois databases - Looking at the pieces


    (Page 5 of 7 )


    main.whois

    The base class is class "Whois" defined in main.whois. We've intentionallyupper-cased the "W" which means that if can begin working with this in your existing scripts, the new class will not collide with anything thatmay be using the old version 1 whois.php3.

    The $Query variable is a hash that functions more or less as the localenvironment for the object. It keeps track of things like what our current whois server is ($Query["server"]), what the current TLD is($Query["tld"], not as obvious as you might think at first glance, considering the nominet uk.com and gb.net, which we support),what the actual query is ($Query["string"]) and last but definatelynot least, an array of any errors encountered in $Query["errstr"].

    We invoke the class in the normal method, and pass our query as well:

    $whois = new Whois("devshed.com");
    In PHP we can create constructors for our classes by putting a functionin the class with the same name as the class. We rely heavily on thosehere and in our first constructor we basically get everything readyfor a normal domain lookup (we don't have to invoke the class this waybut for our purposes we'll just look at domain lookups in normal fashionfor now).

    class Whois { .. .. .. function Whois ($query="") { require("servers.whois"); $this->VERSION=sprintf("Whois2.php v%s:%s", $this->CODE_VERSION, $this->DATA_VERSION); if(isSet($query)) { $this->Query["string"]=strtolower($query); $tld=$this->GetTld($this->Query["string"]); if($tld) { $this->Query["server"]=$this->DATA[$tld][0]; if(isSet($this->DATA[$tld][1])) { $handler=$this->DATA[$tld][1]; $this->Query["file"]=sprintf("%s.whois",$handler); $this->Query["handler"]=$handler; } $this->Query["tld"]=$tld; } else { $this->Query["status"]=-1; $this->Query["errstr"][]=$this->Query["string"]. " domain is not supported"; unset($this->Query["server"]); } } else { $this->Query["server"]=$this->NSI_REGISTRY; } }
    So we set the TLD, set the current whois server, and if we have one,we define an extended handler. The whois.main then takes care of thebasic tasks that we need to do regardless of what we're doing it to: connect to the server with Connect(), send the query string and read back the output with Lookup(), and then, if we have an extended handler,pass the result to Process().

    servers.whois

    One of the first orders of business to to load the "servers.whois" file.This contains the $DATA array which is an array indexed by supported TLD's, the values of which are arrays with their corresponding whoisserver as their first value, and an optional "extended handler" asvalue 2. We want to keep all this in a seperate file because thisdata will take on an update history seperate from the code itself,as new whois servers are reported and (hopfully) energetic PHP codersprovide additional extended classes for various TLDs and registrars.

    extended handlers

    The extended handlers demonstrate PHP extended classes and inheritance.Because output varies wildy from server to server, we provide additionalprocessing of raw output via modular and extensible "handlers", which in themselves, can utilize even further handlers.

    Take "devshed.com" as our example again. We know from using the informationin the $DATA array that it will be queried at whois.nsiregistry.net, thecentral registry server. We also see that there is an extended handler"gtld" specified for this TLD. So the Process() function is going toload the code in gtld.whois and then invoke an instance of the gtldclass which extends the whois class.

    if(!defined("__GTLD_HANDLER__")) define("__GTLD_HANDLER__",1); class gtld extends Whois { var $HANDLER_VERSION = "1.0"; .. .. function gTLD ($data,$query) { $this->Query=$query; $this->SUBVERSION = sprintf("%s-%s", $query["handler"], $this->HANDLER_VERSION); $this->result["regyinfo"]=$this->ParseRegInfo($data["rawdata"]); if($this->HACKS["nsi_referral_loop"] && $this->result["regyinfo"]["whois"]== $this->HACKS["wrong_netsol_whois"] ) { $this->Query["server"]=$this->HACKS["real_netsol_whois"]; } else { $this->Query["server"]=$this->result["regyinfo"]["whois"]; } $this->result["rawdata"]=$this->Lookup($this->Query["string"]); $this->Query["handler"] = $this->REGISTRARS[$this->result["regyinfo"]["registrar"]]; if(!empty($this->Query["handler"])) { $this->Query["file"]=sprintf("%s.whois", $this->Query["handler"]); $this->result["regrinfo"]=$this->Process($this->result["rawdata"]); } }
    Once again there is a class constructor in class gltd, and we parse the registry output in to key/value pairs. It also turns out that the registrar for devshed.com happens to be Network Solutions, and as it so happens, wehave yet another extended class "netsol" so we query that server, get theresults, and and hand it off to class "netsol" parse it into key/value pairs as well.

    The gtld object uses it's inherited Process() and Lookup() methods to do the follow-up query to the appropriate whois server, and if that'sit, it would stop there, returning the raw output. But in this casethe gtld class does have a "netsol" handler to further process the data, so it hands off to it for parsing.

    We can then add further handlers for ICANN accredited registrars by addingthem $REGISTRARS array of the gtld, much in the fashion we can add additionalccTLD handlers to the $DATA array.

    More PHP Articles
    More By Mark Jeftovic


     

       

    PHP ARTICLES

    - Using Aliases and the Autoload Function with...
    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Sub Classing Exceptions in PHP 5
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT