2
0
forked from Wavyzz/dolibarr

Added : url string validation

This commit is contained in:
Regis Houssin
2009-04-03 12:56:21 +00:00
parent c76caf0c9b
commit 282871a8c4
6 changed files with 109 additions and 57 deletions

View File

@@ -2379,13 +2379,60 @@ function clean_url($url,$http=1)
}
// On passe le nom de domaine en minuscule
$url = eregi_replace('^'.$proto.$domain, $newproto.strtolower($domain), $url);
$CleanUrl = eregi_replace('^'.$proto.$domain, $newproto.strtolower($domain), $url);
return $url;
return $CleanUrl;
}
}
/**
* \brief Url string validation
* \remarks <http[s]> :// [user[:pass]@] hostname [port] [/path] [?getquery] [anchor]
* \param url Url
* \param http 1: verify http, 0: not verify http
* \param pass 1: verify user and pass, 0: not verify user and pass
* \param port 1: verify port, 0: not verify port
* \param path 1: verify path, 0: not verify path
* \param query 1: verify query, 0: not verify query
* \param anchor 1: verify anchor, 0: not verify anchor
* \return string ValidUrl
*/
function valid_url($url,$http=0,$pass=0,$port=0,$path=0,$query=0,$anchor=0)
{
$ValidUrl = 0;
$urlregex = '';
// SCHEME
if ($http) $urlregex .= "^(http:\/\/|https:\/\/)";
// USER AND PASS
if ($pass) $urlregex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)";
// HOSTNAME OR IP
//$urlregex .= "[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*"; // http://x = allowed (ex. http://localhost, http://routerlogin)
//$urlregex .= "[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)+"; // http://x.x = minimum
$urlregex .= "([a-z0-9+\$_-]+\.)*[a-z0-9+\$_-]{2,3}"; // http://x.xx(x) = minimum
//use only one of the above
// PORT
if ($port) $urlregex .= "(\:[0-9]{2,5})";
// PATH
if ($path) $urlregex .= "(\/([a-z0-9+\$_-]\.?)+)*\/";
// GET Query
if ($query) $urlregex .= "(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)";
// ANCHOR
if($anchor) $urlregex .= "(#[a-z_.-][a-z0-9+\$_.-]*)\$";
// check
if (eregi($urlregex, $url))
{
$ValidUrl = 1;
}
return $ValidUrl;
}
/**
* \brief Clean a string from all HTML tags and entities