Forum Moderators: coopster
This is a function part of a class calling WHOIS
I remodified it to fit a simple function() environemt for test purpose
but cannot go farther than line 2 due to that missing argument
although it passes ok so why am I generating an error
<? error_reporting(E_ALL);
function whois ($a_server, $a_url, $a_port=43)
{
global $result;
$available = "No match";
$available2 = "Not found";
$a_url = str_replace("www.", "", $a_url);
$a_url = str_replace("http://", "", $a_url);
$whois_servers = Array(
'com' => 'whois.internic.net',
'net' => 'whois.internic.net',
'edu' => 'whois.educause.edu',
'org' => 'whois.publicinterestregistry.net');
global $whois_servers;
@reset($whois_servers);
$a_url = $a_url . "." . $a_server;
$a_server = $whois_servers[$a_server];
$sock = @fsockopen($a_server,$a_port);
IF (!$sock) {
echo ("<b>Could Not Connect To Server.</b>");
}
ELSE {
$send_request =@fputs($sock,"$a_url\r\n");
IF (!$send_request) {
echo ("<B>Unable to send request.</B>");
}
ELSE {
while(!feof($sock)) {
$result .= fgets($sock,128);
}
$result = str_replace("\n", "<br>", $result);
IF (@eregi($available,$result) OR @eregi($available2,$result)) {
$result = 1;
}
ELSE {
$result = 0;
}
@fclose($sock);
}
}
return ($result);
}
//} // ends class
?>
<?
$a_url=$_POST['url'];
echo"$a_url";
// WHOIS
$url= whois($a_url);
/*if
($result == 1)
{ echo "1";}
else
{ echo "0"; } */
?>
When you call the function, you need to match the parameters in the calling statement with the parameters in the function declaration statement in the exact order.
Your calling statement is;
$url= whois($a_url);
Your function declaration is
function whois ($a_server, $a_url, $a_port=43)
So, the compiler is trying to match "$a_url" in the calling statement with "$a_server" in the declaration statement. It then finds no second parameter to match to "$a_url". "$a_port" is uneccessary in the calling statement since you've given it a value in the function declaration. Try this instead:
$url = whois($a_server,$a_url);
That should work.
{
global $result;
$available = "No match";
$available2 = "Not found";
$a_url = str_replace("www.", "", $a_url);
$a_url = str_replace("http://", "", $a_url);
$whois_servers = Array(
'com' => 'whois.internic.net',
'net' => 'whois.internic.net',
'edu' => 'whois.educause.edu',
'org' => 'whois.publicinterestregistry.net');
global $whois_servers;
@reset($whois_servers);
$a_url = $a_url . "." . $a_server;
$a_server = $whois_servers[$a_server];
//echo" A_S $a_server";
$sock = @fsockopen($a_server,$a_port);
IF (!$sock) {
echo ("<b>Could Not Connect To Server.</b>");
}
ELSE {
$send_request =@fputs($sock,"$a_url\r\n");
//echo"SR $send_request";
IF (!$send_request) {
echo ("<B>Unable to send request.</B>");
}
ELSE {
while(!feof($sock)) {
$result .= fgets($sock,128);
}
$result = str_replace("\n", "<br>", $result);
IF (@eregi($available,$result) OR @eregi($available2,$result)) {
$result = 1;
}
ELSE {
$result = 0;
}
@fclose($sock);
}
}
return ($result);
}
//} // ends class Screen
?>
<?
$a_url=$_POST['url'];
// WHOIS
$a_url2= whois($a_server,$a_url);
?>
Line 92 is the last one, calling the function.
<?
$a_url=$_POST['url'];
$a_server = ltrim(substr($a_url, -3), ".");
// WHOIS
$a_url2= whois($a_server,$a_url);
?>
Gets three last letters. if it's eu, then trims the dot and leaves eu.
At least it should, but I haven't tested it.
Michal
$a_server is defined by:
<<<<
$a_url = str_replace("www.", "", $a_url);
$a_url = str_replace("http://", "", $a_url);
$whois_servers = Array(
'com' => 'whois.internic.net',
'net' => 'whois.internic.net',
'edu' => 'whois.educause.edu',
'org' => 'whois.publicinterestregistry.net');
global $whois_servers;
@reset($whois_servers);
$a_url = $a_url . "." . $a_server;
$a_server = $whois_servers[$a_server];
>>>>
Do we really need to trim it? $a_server should be containing the proper info.
<?// error_reporting(E_ALL);
function whois ($a_url, $a_server, $a_port=43)
{
global $result;
$available = "No match";
$available2 = "Not found";
$a_url = str_replace("www.", "", $a_url);
$a_url = str_replace("http://", "", $a_url);
switch (true) {
case preg_match("/.com/i", $a_url):
$a_server="whois.internic.net"; //echo "$a_server";
break;
case preg_match("/.net/i", $a_url):
$a_server="whois.internic.net"; //echo "$a_server";
break;
case preg_match("/.org/i", $a_url):
$a_server="whois.publicinterestregistry.net"; //echo "$a_server";
break;
case preg_match("/.edu/i", $a_url):
$a_server="whois.educause.edu"; //echo "$a_server";
break;
default:
echo 'default';
break;
}
$sock = @fsockopen($a_server,$a_port);
IF (!$sock) {
echo ("<b>Could Not Connect To Server.</b>");
}
ELSE {
$send_request =@fputs($sock,"$a_url\r\n");
IF (!$send_request) {
echo ("<B>Unable to send request.</B>");
}
ELSE {
while(!feof($sock)) {
$result .= fgets($sock,128);
}
$result = str_replace("\n", "<br>", $result);
IF (@eregi($available,$result) OR @eregi($available2,$result)) {
$result = 1;
}
ELSE {
$result = 0;
}
@fclose($sock);
}
}
return ($result);
} // ends class
?>