Forum Moderators: coopster

Message Too Old, No Replies

is submited URL real

not well formed but does it exist?

         

henry0

4:28 pm on Oct 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am building a URL “Bank”
Before loading the URL in the DB
How could I check if an URL is not fake?
I do not look for a regex checking if it is well formed, if it contains bad words etc.. that's already done.
But for a way to check if an URL exists

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!

whoisgregg

5:41 pm on Oct 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The only way to know for sure is for the server to request that URL. :)

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);
}

henry0

7:08 pm on Oct 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Very interesting, thanks whoisgregg.