Forum Moderators: coopster

Message Too Old, No Replies

Function missing argument

but it's there!

         

henry0

7:39 pm on Oct 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Missing argument 2 on line 2 ... is $a_url

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"; } */
?>

brevetoxin

8:19 pm on Oct 26, 2006 (gmt 0)

10+ Year Member



Henry,

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.

henry0

8:41 pm on Oct 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, I should have del the checking value section for I knew and commmented it already

But still get a cannot connect
and since my errors are wide open on the test server
I get a
Undefined variable: a_server in /#*$!#*$!#*$!/test/whois.inc.php on line 92

and then of course cannot connect!

brevetoxin

9:53 pm on Oct 26, 2006 (gmt 0)

10+ Year Member



Can you post your new code, especially the offending line 92?

henry0

9:57 pm on Oct 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<? 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];

//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.

mcibor

10:16 pm on Oct 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You haven't defined the variable $a_server before 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

henry0

10:45 pm on Oct 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mcibor, your version takes care of the undefined $a_server but as is I still cannot connect to server.

$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.

henry0

7:19 pm on Oct 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Done!
Feel free to use the function for ex to dev your own WHOIS or check if a DN is for "real"
I modified quite few lines mostly passing the search via preg_match() and a switch

<?// 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

?>