Forum Moderators: coopster
For example if checking an email I use
<<<
// Validate the syntax
if (eregi($regexp, $email))
{
list($username,$domaintld) = split("@",$email);
// Validate the domain
if (getmxrr($domaintld,$mxrecords))
$valid = 1;
} else {
$valid = 0;
}
return $valid;
}
>>>
Anything in the same range?
How will you go to check if an URL is real, short of using “C” or “JAVA” validators!
To follow the analogy of your email example, you can first use a regular expression to validate the URL. Although parse_url is "not meant to validate the URL" the manual page for parse_url [php.net] has some examples in the comments for how to validate a URL.
Next, to accomplish the same thing that getmxrr does for emails, you can actually check the exact URL by having the server fetch that URL. Something like the example on the fsockopen [us2.php.net] manual page should get you started:
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
// it failed, the error number is held in $errno
echo "$errstr ($errno)<br />\n";
} else {
// then it was successful!
fclose($fp);
}