webdev007
Programmer
- Sep 9, 2005
- 168
I have a class that performs a few actions
I stripped it down to isolate my problem
I know that it works as a standalone function.
But in the class environment when performing a WHOIS
Regardless of the result to be 1 or 0 it always returns 1
it connect ok to the WHOIS servers
The first piece of code is the class
The second code calls it
Thank you to provide some “lights”![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
I stripped it down to isolate my problem
I know that it works as a standalone function.
But in the class environment when performing a WHOIS
Regardless of the result to be 1 or 0 it always returns 1
it connect ok to the WHOIS servers
The first piece of code is the class
The second code calls it
Thank you to provide some “lights”
Code:
<?
class CheckUrl
{
var $url;
var $url_preg;
var $text;
var $badWords;
var $a_server;
// Check for duplicate of URL
// DUPLI CHECK **********
// BAD WORDS FILTER
// WHOIS URL checking
function whois ($url, $a_server, $a_port=43)
{
global $result;
$available = "No match";
$available2 = "Not found";
$this->url=$url;
$url = str_replace("[URL unfurl="true"]www.",[/URL] "", $url);
$url = str_replace("[URL unfurl="true"]http://",[/URL] "", $url);
switch (true) {
case preg_match("/.com/i", $url):
$a_server="whois.internic.net"; //echo "$a_server";
break;
case preg_match("/.net/i", $url):
$a_server="whois.internic.net"; //echo "$a_server";
break;
case preg_match("/.org/i", $url):
$a_server="whois.publicinterestregistry.net"; //echo "$a_server";
break;
case preg_match("/.edu/i", $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,"$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 function
} // ends class
?>
Code:
<? // USING THE CLASS ?>
<?
//error_reporting (E_ALL);
include"check_url.inc.php"; // the class
$test=$_POST['url'];
$url2 = new CheckUrl($test, $a_server);
$a_server = ltrim(substr($test, -3), ".");
$url2->whois($test, $a_server);
echo "$result"; //used in test mode
if
($result == 1)
{
// then it exists, do nothing! // in test mode use echo"$result";
}
if($result == 0)
{
echo "Not ok";
exit();
}
?>