WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : base class to query the whois database
Categories : Network, PHP, PHP Classes Update Picture
Mark Jeftovic
Date : Jan 17th 1999
Grade : 2 of 5 (graded 5 times)
Viewed : 8343
File : whois.php3
Images : No Images for this code example.
Search : More code by Mark Jeftovic
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?php
//
// whois.php3 v1.4b3 1999/01/05
//
// Copyright (c) 1998 Mark Jeftovic / Private World Communications
// email: markjr@privateworld.com
//
// For most recent version check: http://www.shmOOze.net/~markjr/whois/
//
// All rights reserved.
// This code provided "As Is" with no warrantees express or implied.
// The author and contributors are not liable for anything good or
// bad that results from your use of this code.
//
// You are free to distribute this for free provided this notice is
// included. Please forward fixes/enhancements to the author for
// inclusion in the next revision.
//
// CHANGES:
// 1.4b3 -(01/05/99): Internic chenged the "Too Busy" message wording
// again. Reported by Gregory A. Carter <omni@dynmc.net>
// 1.4b2 -(08/24/98): put the old code back in parse_contact_line() with
// a bit ofa modification (the version in 1.4b couldn't parse
// the result from doing a rawlookup() on a nic handle properly)
// 1.4b - (08/17/98): added ability to cache results, set $whois->use_cache
// and rawlookup() will
// a) check the cache_dir for a previously cached zone file
// and use it if it finds it, sets $whois->FROM_CACHE
// b) write a zone record there after it looks it up
// It's up to the user to expire the cache (i.e. cron job to delete
// entries older than x seconds)
// -TODO: if caching is turned on and $whois->HANDLES is set (query
// returned multiple handles) the result still gets cached. I don't
// want this but it happens anyways. This is probably a bug.
// - pushed default server (whois.internic.net) from param to connect()
// to rawlookup(), because i realized you couldn't do rawlookup()
// to other whois servers the old way. For now just use:
// $whois->rawlookup("example.ca", "whois.cdnnet.ca") to do
// alternate lookups
// -parse_contact_line() rewritten by Ben Ginter <bginter@abilnet.com>
// (although I added the chop()'s, some code here broke without them)
// 1.3 - (07/28/98): the whois server is starting to spit out a couple
// or few blank lines and then dying, which wouldn't set
// $whois->ERROR, even though it should, so now it does
// 1.2 - format change on Internic side, Organization info preceded by
// a "Registrant:" line.
// 1.1 - couple of bugfixes by Colin Viebrock <cmv@privateworld.com>
// ORG_ADDRESS wasn't getting caught because of a typo
//
// added trim() function (now internal to php anyways i think)
//
// USAGE:
// $domain = "somedomain.com";
// $whois = new whois;
//
// the following line simply loads an array with the raw output of
// a whois query and sets $whois->FOUND (if the query finds no
// match $whois->FOUND will be 0) if an error occurs in the lookup
// $whois->ERROR will be set.
// $array = $whois->rawlookup($domain)
//
// this parses the array into variables available to the package:
// $whois->parsezone($array);
//
// will set vars such as $whois->ORGANIZATION, $whois->ORG_HANDLE
// $whois->DOMAIN_NAME, the hashes $whois->TECH, $whois->ADMIN, etc.
// and the arrays: $whois->DNS_NAME and $whois->DNS_IP
// (for a complete list, see below)
//
// you can complete both steps (rawlookup and parsezone) with:
// $whois->zonelookup($domain);
//
// TODO:
// - support to parse other types of queries (host, contact, etc)
// (you can still use rawlookup for these types of handles)
// - support for alternate servers/queires (i.e. netblocks via
// whois.arin.net)
//
class whois {

var $use_cache = 1;
var $FROM_CACHE=0;
var $cache_dir = "/var/spool/whois";

var $port = 43;
var $MAXLEN = 80;

// if we want to automagically retry after a failed connect then
// set $MAX_RETRIES the number of retries you want
var $MAX_RETRIES = 0;
var $SLEEP_VAL = 1;
var $RETRY = 0;

var $FOUND = 0; // this will be 0 if the query yields no match
var $ERROR = 0; // this will be set if an error occurs in the lookup
var $DATA_MIN = 8; // we should at least this many bytes of data, or
// we assume the whois server just spit out nothing
// and died (which it's starting to do more often)
var $DATA_COUNT = 0;

// these are the vars set when you parse the results of a domain lookup
var $ORGANIZATION;
var $ORG_HANDLE;
var $ORG_ADDRESS; // array that holds the org's address info
var $DOMAIN_NAME;
var $DOMAIN_STATUS;
var $ADMIN; // hash with subscripts: "name", "nic" and "email"
var $TECH; // hash with subscripts: "name", "nic" and "email"
var $ZONE; // hash with subscripts: "name", "nic" and "email"
var $BILLING;
var $UPDATED;
var $CREATED;
var $DNS_NAME; // array of nameserver hostnames (primary first)
var $DNS_IP; // array of nameserver ips (primary first)
var $HANDLES; // array of nic handles if a zonelookup yields
// multiple results


// open a socket to the whois server
// defaults to whois.internic.net if an alternate is not passed
// returns: a pointer on success, sets $this->ERROR on fail
function connect ($server) {
while($this->RETRY <= $this->MAX_RETRIES):
$ptr = fsockopen($server, $this->port);
if($ptr>0):
$this->ERROR=0; // just in case we're on a retry
return($ptr);
else:
$this->ERROR++;
$this->RETRY++;
sleep($this->SLEEP_VAL);
endif;
endwhile;
}

// simply gets the output of the query from the whois server
// and loads it into array
function rawlookup ($query,$server= "whois.internic.net") {
if(!$query):
return( "");
endif;
$ptr=$this->connect($server);
if($ptr):
if(!ereg($query, "\n$")):
$query .= "\n";
endif;
fputs($ptr, "$query");
$i=0;
$this->FOUND=1;
while(!feof($ptr)):
$array[$i]=fgets($ptr,$this->MAXLEN);
$this->DATA_COUNT+=strlen(chop($array[$i]));
if(eregi( "No match for", $array[$i])):
$this->FOUND=0;
elseif(eregi( "WHOIS database is down",$array[$i])):
$this->ERROR++;
$this->FOUND=0;
elseif(eregi( "Please wait a while and try again",$array[$i])):
$this->ERROR++;
$this->FOUND=0;
break;
endif;
$i++;
endwhile;
fclose($ptr);
if($this->DATA_COUNT>$this->DATA_MIN):
return($array);
else:
$this->ERROR++;
endif;
else:
$this->ERROR++;
endif;
}

// takes a contact info line from a zone record and parses it
// into name, nic, and email
// reverted to old code with a modified email pattern in 1.4b_2
function parse_contact_line ($line) {
$hash[ "name"]=trim(ereg_replace( "(.+) \(.+", "\\1", $line));
$hash[ "nic"]=ereg_replace( ".+\((.+)\).+", "\\1", $line);
$hash[ "email"]=trim(ereg_replace( ".+\)[[:space:]]+(.+)", "\\1", $line));
return($hash);
}

// parses an array with zone info into the package variables for e-z access
function parsezone ($array) {
if(!$array || !$this->FOUND || $this->ERROR):
return( "");
endif;
// alas, we need to blow through this array twice, the
// first time to determine a few things
$lookahead=0;
while($lookahead<count($array)):
// at what point will we stop assuming input
// gets added to $this->ORG_ADDRESS
if(ereg( "Domain Name: .+",$array[$lookahead])):
$dline=$lookahead;
elseif(ereg( "To single out one record", $array[$lookahead])):
$this->FOUND++;
endif;
$lookahead++;
endwhile;
$i=0;
while($i<count($array)):
if($this->FOUND==1):
if(ereg( "Registrant:", $array[$i])):
list($this->ORGANIZATION,$this->ORG_HANDLE)=split( "\(",$array[$i+1],2);
$this->ORG_HANDLE=ereg_replace( "\)$", "",chop($this->ORG_HANDLE));
$bline=$i+1;
elseif($i>bline && $i<$dline):
$this->ORG_ADDRESS[]=trim($array[$i]);
elseif(ereg( "Domain Name: .+", $array[$i])):
$this->DOMAIN_NAME=ereg_replace( "Domain Name: (.+$))", "\\1",$array[$i]);
elseif(ereg( "Domain Status: .+", $array[$i])):
$this->DOMAIN_STATUS=ereg_replace( "Domain Status: (.+$))", "\\1",$array[$i]);
elseif(ereg( "Record last updated on",$array[$i])):
$this->UPDATED=ereg_replace( "Record last updated on (.+$))", "\\1",$array[$i]);
elseif(ereg( "Record created on",$array[$i])):
$this->CREATED=ereg_replace( "Record created on (.+$))", "\\1",$array[$i]);
elseif(ereg( "Domain servers in listed order:",$array[$i])):
$i++;
while($i<count($array)):
$i++;
if(ereg( ".+\..+\..+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", $array[$i])):
list($this->DNS_NAME[],$this->DNS_IP[])=split( "(\20|\t)+",$array[$i],2);
endif;
endwhile;
endif;

// looks like we can't use backreferences outside the
// regex functions they're used in, so we're kinda
// stuck here and have to put these checks
// outside the above switch. (cause two or more
// of these could appear on the same line)
if(ereg( "Administrative Contact",$array[$i])):
$this->ADMIN=$this->parse_contact_line($array[$i+1]);
endif;
if(ereg( "Technical Contact",$array[$i])):
$this->TECH=$this->parse_contact_line($array[$i+1]);
endif;
if(ereg( "Zone Contact",$array[$i])):
$this->ZONE=$this->parse_contact_line($array[$i+1]);
endif;
if(ereg( "Billing Contact",$array[$i])):
$this->BILLING=$this->parse_contact_line($array[$i+1]);
endif;
else:
if(ereg( ".+\(.+\).+", $array[$i])):
$this->HANDLES[]=ereg_replace( ".+\((.+)\).+", "\\1",$array[$i]);
$this->FOUND++;
endif;
endif;
$i++;
endwhile;
// we still get spurious blank results, so we'll check that
// the nic handles aren't null and set $this->ERROR if they are
if(!count($this->ADMIN) || !count($this->TECH)) { $this->ERROR++; }
}

// does rawlookup() and passes the resultant array to parsezone()
function zonelookup ($query) {
if($this->use_cache):
$rawinfo = $this->cache_lookup(strtolower(chop($query)));
if($this->FOUND && !$this->FROM_CACHE && !$this->HANDLES):
$this->cache_write($query, $rawinfo);
endif;
else:
$rawinfo = $this->rawlookup($query);
endif;
if($this->FOUND):
$this->parsezone($rawinfo);
endif;
}

function cache_lookup ($query) {
$cache_file = $this->cache_dir . "/". $query;
if(file_exists($cache_file)):
$this->FROM_CACHE=1;
$this->FOUND=1;
return(file($cache_file));
else:
$rawinfo = $this->rawlookup($query);
if(!$this->ERROR && $this->FOUND):
return($rawinfo);
endif;
endif;
}


function cache_write ($query, $rawinfo) {
$fp = fopen( "$this->cache_dir/$query", "w");
for($i=0,$num=count($rawinfo);$i<$num;$i++) {
fputs($fp, $rawinfo[$i]);
}
}

};

?>



Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip
Categories : Email, Network, PHP, PHP Classes
Client classes for Dictionary servers UPDATED: 2000-06-06
Categories : Network, Search, Complete Programs, PHP Classes, PHP
Sample usage of IPv6 and IPv4 with PHP
Categories : PHP, PHP Classes, Network
Class that allows the PHP developer to establish connections with a POP3 mail server amd be able to list, retrieve and delete mail messages from a given mail box.
Categories : Network, Email, PHP, PHP Classes
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
Authorize.net AIM Interface Class v1.0.0
Categories : PHP, PHP Classes, Ecommerce, Payment Gateways
A simple class with some HTML output functions that would come in handy for consistent page layout etc.
Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation
crop and resize image class using gd library function
Categories : PHP, PHP Classes, GD image library, Graphics
Excel class in PHP
Categories : PHP, PHP Classes, Excel
News management class
Categories : PHP, PHP Classes, Beginner Guides
Expose - PHP template engine, supports server and client-sided caching,a plugin system, multiple languages, template script language is based on PHP itself.
Categories : PHP, PHP Classes, Templates, Complete Programs
Simple Template Class/Example
Categories : PHP, Templates, PHP Classes
MS Word Mail Merge Automation (COM)
Categories : PHP, PHP Classes, COM
Very minimal templating engine
Categories : PHP, PHP Classes, Templates
XPath for PHP without the DOM XML extension
Categories : DOM XML, XML, XSLT, PHP Classes, PHP
 mark exley wrote : 444
this script doesnt seem to work as anything that i search for shows up as already registered ie reteetrehh1232kgferk shows every type of domain associated with it as registered    any ideas as to what is wrong with the script?
 
 mark exley wrote :445
my mistake this refers to the other whois script sorry