- corrected validation of Domain and URL (stupid php-bug)

This commit is contained in:
Michael Kaufmann (d00p)
2010-05-04 09:54:10 +00:00
parent 7ea04992e3
commit 9c79654cf4
2 changed files with 15 additions and 30 deletions

View File

@@ -39,22 +39,13 @@ function validateDomain($domainname)
// there is a bug in php 5.2.13 - 5.3.2 which // there is a bug in php 5.2.13 - 5.3.2 which
// lets filter_var fail if the domain has // lets filter_var fail if the domain has
// a dash (-) in it. # // a dash (-) in it. As the PHP_VERSION constant
if(version_compare("5.2.13", PHP_VERSION, "=") // gives also patch-brandings, e.g. '5.3.2-pl0-gentoo'
|| version_compare("5.3.2", PHP_VERSION, "=")) // we just always use our regex
{ $pattern = '/^http:\/\/([a-z0-9]([a-z0-9\-]{0,61}[a-z0-9])?\.)+[a-z]{2,6}$/i';
$pattern = '/^http:\/\/([a-z0-9]([a-z0-9\-]{0,61}[a-z0-9])?\.)+[a-z]{2,6}$/i'; if(preg_match($pattern, $domainname_tmp))
if(preg_match($pattern, $domainname_tmp)) {
{ return $domainname;
return $domainname;
}
}
else
{
if(filter_var($domainname_tmp, FILTER_VALIDATE_URL) !== false && filter_var($domainname_tmp, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) === false && filter_var($domainname_tmp, FILTER_VALIDATE_URL, FILTER_FLAG_QUERY_REQUIRED) === false)
{
return $domainname;
}
} }
return false; return false;
} }

View File

@@ -34,21 +34,15 @@ function validateUrl($url)
$url = 'http://' . $url; $url = 'http://' . $url;
} }
if(version_compare("5.2.13", PHP_VERSION, "=") // there is a bug in php 5.2.13 - 5.3.2 which
|| version_compare("5.3.2", PHP_VERSION, "=")) // lets filter_var fail if the domain has
// a dash (-) in it. As the PHP_VERSION constant
// gives also patch-brandings, e.g. '5.3.2-pl0-gentoo'
// we just always use our regex
$pattern = '/^https?:\/\/([a-z0-9]([a-z0-9\-]{0,61}[a-z0-9])?\.)+[a-z]{2,6}$/i';
if(preg_match($pattern, $url))
{ {
$pattern = '/^https?:\/\/([a-z0-9]([a-z0-9\-]{0,61}[a-z0-9])?\.)+[a-z]{2,6}$/i'; return true;
if(preg_match($pattern, $url))
{
return true;
}
}
else
{
if(filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED) !== false)
{
return true;
}
} }
// not an fqdn // not an fqdn