<?php
$domain = "www.phpbuilder.org";
function is_valid($domain) {
$elements = split("\.", $domain);
$parts = count($elements);
if ($parts < 2) {
return 0;
}
for ($i = 0; $i < $parts - 1; $i++) {
if (strlen($elements[$i]) < 1) {
return 0;
}
if (!ereg("([a-zA-Z0-9-]{1,255})", $elements[$i], $regs)) {
return 0;
}
}
return 1;
}
/* warning, this can be exploited */
function lookup_in_dns($domain) {
$result = `nslookup -sil $domain | sed -n '5p'`;
/* length of result = 1 if empty */
if (empty($result) || strlen($result) < 2) {
return 0;
}
return 1;
}
$back = is_valid($domain);
$back2 = lookup_in_dns($domain);
echo "Back: $back & $back2<br>";
?>
Just some dirty code...
I think that it works...
lookup_in_dns is a bit ugly and could very well be exploited right now by entering a domainname like "www; rm -rf /" but using nslookup or another tool is the only way I can come up with that makes sure that the domainname is valid and isn't just syntax correct.
Good luck.