- 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
// lets filter_var fail if the domain has
// a dash (-) in it. #
if(version_compare("5.2.13", PHP_VERSION, "=")
|| version_compare("5.3.2", PHP_VERSION, "="))
{
$pattern = '/^http:\/\/([a-z0-9]([a-z0-9\-]{0,61}[a-z0-9])?\.)+[a-z]{2,6}$/i';
if(preg_match($pattern, $domainname_tmp))
{
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;
}
// 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 = '/^http:\/\/([a-z0-9]([a-z0-9\-]{0,61}[a-z0-9])?\.)+[a-z]{2,6}$/i';
if(preg_match($pattern, $domainname_tmp))
{
return $domainname;
}
return false;
}

View File

@@ -34,21 +34,15 @@ function validateUrl($url)
$url = 'http://' . $url;
}
if(version_compare("5.2.13", PHP_VERSION, "=")
|| version_compare("5.3.2", PHP_VERSION, "="))
// there is a bug in php 5.2.13 - 5.3.2 which
// 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';
if(preg_match($pattern, $url))
{
return true;
}
}
else
{
if(filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED) !== false)
{
return true;
}
return true;
}
// not an fqdn