Simple WHOIS
PHP gives us the opportunity to run a shell command, for example with exec() function. Let's try it and write a simple whois service. Whois - is a *nix command which will show us the information about domain registration. Also we can check if the domain is free. Remember to check if your hosting provider turned exec() on. Usually this function is in disable_functions parameter in php.ini file. And also try if whois is allowed and works ok on your server. I tried it locally on Apache 2, PHP 5, Linux Fedora 8 and everything was fine.
So we're going to create page with form to input the domain name.
Of course we need to check if domain name is correct, otherwise someone can make an injection and damage our system using OS commands.
Also we will check if exec() PHP command is turned on.
-
<?
-
if (isset($_GET['domain'])) // if we have entered not a domain, but URL let's taking away http://www.
-
{
-
}
-
// form output
-
echo '<form name="domaincheck" action="whois.php" method="get">';
-
echo '<input type="text" name="domain" size="50" value="';
-
echo '">
-
<input type="submit" value="Check">
-
</form><br /><br />';
-
// is exec() turned on ?
-
echo "ERROR: exec() is not available!";
-
}
-
else
-
{
-
echo "ERROR: domain is not specified";
-
}
-
else {
-
if (!eregi("^[a-z0-9.-]*$",$_GET['domain'])) { // simple domain check: only letters,digits and ".", "-"
-
echo "ERROR: incorrect domain!";
-
}
-
else {
-
foreach ($output as $line) // let's print each line
-
}
-
}
-
}
-
?>