Forum Moderators: coopster

Message Too Old, No Replies

modifying this php whois lookup script

         

lindajames

9:28 pm on Aug 14, 2003 (gmt 0)

10+ Year Member



hi,

i have the following whois lookup script, that can check check the availablity of a domain by calling the script like this: index.php?domain=domain&ext=com&option=check and basically if the domain is available it displays a link to order it if not it displays a link to check the whois details on it.

The only problem with the script is that when it is run like index.php?domain=s&ext=com&option=check the extension is specified as a param, can someone help me to convert this code so that i can somehow search for more than one extension at the same time e.g.

index.php?domain=s&ext=com&ext=net&ext=org&option=check

any help would be appreciated.

cheers
linda

if ($_SERVER['REQUEST_METHOD'] == 'GET'){
$domain = $_GET['domain'];
$ext = $_GET['ext'];
$option = $_GET['option'];
}else{
$domain = $_POST['domain'];
$ext = $_POST['ext'];
$option = $_POST['option'];
}
if($restrict ==1){
check_referer();
}
namecheck($domain);
if(($ext=="co.ug")¦¦($ext=="or.ug")¦¦($ext=="ac.ug")¦¦($ext=="sc.ug")¦¦($ext=="ne.ug")){
$server=$ugserver;
$nomatch=$ugnomatch;
}
if($ext=="co.uk"){
$server=$ukserver;
$nomatch=$uknomatch;
}
if($ext=="com"¦¦$ext=="net"){
$server=$intserver;
$nomatch=$intnomatch;
}
if($ext=="org"){
$server=$orgserver;
$nomatch=$orgnomatch;
}
if($ext=="biz"){
$server=$bizserver;
$nomatch=$biznomatch;
}
if($ext=="info"){
$server=$infoserver;
$nomatch=$infonomatch;
}
if($option=="check"){
$layout = check_domain($domain,$ext);
print_results($layout);
}
if($option=="whois"){
whois($domain,$ext);
}
//end main script area---->

//<------------------------------------functions-------------------------------->
function check_domain($domain,$ext)
{
global $nomatch,$server;
$output="";
if(($sc = fsockopen($server,43))==false){echo"The script could not connect to whois server : $server";exit;}
fputs($sc,"$domain.$ext\n");
while(!feof($sc)){$output.=fgets($sc,128);}
fclose($sc);
//compare what has been returned by the server
if (eregi($nomatch,$output)){
return 0;
}else{
return 1;
}
}

function whois($domain,$ext)
{ global $template,$server;
if(($sc = fsockopen($server,43))==false){
if(($sc = fsockopen($server,43))==false){
echo"There is a temporary service disruption Please again try later";
exit;
}
}
if($ext=="com"¦¦$ext=="net"){
//
fputs($sc, "$domain.$ext\n");
while(!feof($sc)){
$temp = fgets($sc,128);
if(ereg("Whois Server:", $temp)) {
$server = str_replace("Whois Server: ", "", $temp);
$server = trim($server);
}
}
fclose($sc);
if(($sc = fsockopen($server,43))==false){
echo"There is a temporary service disruption Please try later";
exit;
}
}

$output="";
fputs($sc,"$domain.$ext\n");
while(!feof($sc)){$output.=fgets($sc,128);}
fclose($sc);
//print
if(!is_file($template)){
print"The template file into which to print the results either does not exist
or is not writable<br>
please correct this if you are the webmaster of this site<br>
The script can not continue exiting......";
exit;
}
$template = file ($template);
$numtlines = count ($template);
$line = 0;
while (! stristr ($template[$line], "<!--DOMAIN RESULTS-->") && $line < $numtlines) {
echo $template[$line];
$line++;
}
$line++;
print "<div align=\"center\">";
print "<table width=\"100%\" border=\"0\" cellPadding=2 class=font1l>";
print "<tr><td><b>Domain whois query information for \"$domain.$ext\"</b></td></tr>";
print "<tr><td><hr></td></tr><br>";
print "<tr><td>";
$output= explode("\n",$output);
foreach ($output as $value){
print "$value<br>\n";
}
print "</td></tr></table>";
print "</div>";
print "<br>";
print "<center></center>";
while ($line < $numtlines) {
echo $template[$line];
$line++;
}

}
//function to check referer
function check_referer () {
global $REFERERS, $HTTP_REFERER;
if ($HTTP_REFERER!= "")
while (list($val, $ref) = each($REFERERS))
if (preg_match("/^http:\/\/$ref/", $HTTP_REFERER))
return;
print("Access denied to: $HTTP_REFERER<br>Please dont link to this script <a href=\"scripts.php\">download</a> a copy
and set it up on your site.<br> This is due to bandwidth usage ... leeching and Data mining");
exit;
}
//Function to print the results into your template
function print_results($layout)
{
global $template,$registerlink,$domain,$ext;
if(!is_file($template)){
print"The template file into which to print the results either does not exist or is
not writeable<br>
please correct this if you are the webmaster of this site<br>
The script can not continue exiting......";
exit;
}
$template = file ($template);
$numtlines = count ($template);//Number of lines in the template
$line = 0;
while (! stristr ($template[$line], "<!--DOMAIN RESULTS-->") && $line < $numtlines) {
echo $template[$line];
$line++;
}
if($layout==0){
$line++;
print "<table width=\"100%\" border=\"0\" cellPadding=2 class=font1l>";
print "<tr><td>The domain is available <a href=\"$registerlink?domain=$domain.$ext\">register</a> it now</td></tr>";
print "</table>";
}
if($layout==1){
$line++;
print "<table width=\"100%\" border=\"0\" cellPadding=2 class=font1l>";
print "<tr><td><b>The domain is already taken <a href=\"$PHP_SELF?domain=$domain&ext=$ext&option=whois\">Check</a> the whois information<br></td></tr>";
print "<tr><td>Check another domain name <a href=\"javascript:history.back()\">here</a></td></tr>";
print "</table>";
}
print "<br><br>";
print "<center></center>";
while ($line < $numtlines) {
echo $template[$line];
$line++;
}
}
//This checks the name for invaild characters
function namecheck($domain)
{
if($domain==""){echo"You must enter a domain to be checked<br>\n";
echo"Click <a href=\"javascript:history.back()\">here</a> to go back"; exit;}
if(strlen($domain)< 3){echo"The domain name $domain is too short"; exit;}
if(strlen($domain)>57){echo"The domain name $domain is too long"; exit;}
if(@ereg("^-¦-$",$domain)){echo"Domains cannot begin or end with a hypen"; exit;}
if(!ereg("([a-z]¦[A-Z]¦[0-9]¦-){".strlen($domain)."}",$domain))
{echo"Domain names cannot contain special characters"; exit;}

}

?>

bilalak

5:53 am on Aug 15, 2003 (gmt 0)

10+ Year Member



//
// Add a while loop before the whois function call
// in this snippet
//
if($option=="whois"){
whois($domain,$ext);
}

//
// This would look like
//
if (#option == "whois")
{
foreach ($exts as $ext)
whois($domain, $ext);
}
//
// Done
//

fatdog

2:45 am on Aug 20, 2003 (gmt 0)



Question about function of domain look up script...I am looking to keep it to a simple function. Looking up the domain then when domain is available it automates to a "buy page" the function that I would like to duplicate is found at this site: <snip>

At middle of page CHECK DOMAIN

thanks

john

[edited by: jatar_k at 4:32 pm (utc) on Aug. 20, 2003]
[edit reason] no url's, see TOS [webmasterworld.com] [/edit]