#native_company# #native_desc#
#native_cta#

Simple WHOIS Query (XHTML and PHP4.1.2 Complient)

By Dan Shepherd
on June 5, 2002

Version: 1.1

Type: Sample Code (HOWTO)

Category: Networking

License: GNU General Public License

Description: Displays information on .COM, .ORG, .NET and .EDU domains. Output is returned as XHTML and the script is compatable with PHP 4.1.2

<?php

/*
	A Simple WHOIS Checker (c)2001,2002 Danny Shepherd ([email protected])

	Checks Most Domains (but not .tv)
*/

function whois($name,$server='')
{

	if ($server=='')
	{
		$nameParts=explode(".",$name);
		$tld=$nameParts[count($nameParts)-1];
		$server="$tld.whois-servers.net";
	}

	if($socket=fsockOpen($server,43,$errnum,$errstr,30))
	{
		fputs($socket, "$namern");
		$rawData="";
		while(!feof($socket))
		{
			$thisData=fgets($socket,2048);
			$rawData.=$thisData;

			@list($key,$value)=explode(':',strtolower(eregi_replace(" ",'',$thisData)));

			if (isset($key) && isset($value) && $key=='whoisserver')
			{
				$newServer=trim($value);
				break;
			}
		}

		fclose($socket);

		if (isset($newServer))
			$rawData=whois($name,$newServer);

		return $rawData;
	}
	else
		return "Couldn't open connection to: $server ($errnum: $errstr)!!n";
}

$domain="";
$whoisData="";

if (isset($_REQUEST['domain']) && $_REQUEST['domain']!='')
{
	$domain=$_REQUEST['domain'];
	$whoisData=whois($_REQUEST['domain']);
}

echo <<<EOD
<?xml version="1.0" encoding="iso-8859-1"?>n
<!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" xml:lang="en" lang="en">
	<head>
		<title>Whois Query</title>
	</head>

	<body>
		<form action="{$_SERVER['PHP_SELF']}" method="post">
			Domain Name: <input type="text" name="domain" value="$domain"/>
			<input type="submit" name="submit" value="Check"/>
		</form>

		<hr/>
		<pre>
$whoisData
		</pre>
		<hr/>
	</body>
</html>
EOD;
?>