Since PHP 5.2.0 [url="http://fr.php.net/manual/fr/filter.filters.valiate.php"]FILTER function[/url] are include into PHP.
This allow you to validate more "simply" and quickly (I've done benchmark but I don't keep the result) variables like IP.
In backend/functions.php find :
Be carefull there is a little bug in PHP 5.* and PHP 6 and compatibility with ipv6 :
[url="http://bugs.php.net/bug.php?id=47435"]http://bugs.php.net/bug.php?id=47435[/url]
This is just a little hack for ip validation, but filter php function are very usefull to check integer, string, and POST/GET values...
This allow you to validate more "simply" and quickly (I've done benchmark but I don't keep the result) variables like IP.
In backend/functions.php find :
// IP Validation
function validip($ip)
{
if (!empty($ip) && $ip == long2ip(ip2long($ip)))
{
$reserved_ips = array (
array('0.0.0.0','2.255.255.255'),
array('10.0.0.0','10.255.255.255'),
array('127.0.0.0','127.255.255.255'),
array('169.254.0.0','169.254.255.255'),
array('172.16.0.0','172.31.255.255'),
array('192.0.2.0','192.0.2.255'),
array('192.168.0.0','192.168.255.255'),
array('255.255.255.0','255.255.255.255')
);
foreach ($reserved_ips as $r)
{
$min = ip2long($r[0]);
$max = ip2long($r[1]);
if ((ip2long($ip) >= $min) && (ip2long($ip) <= $max)) return false;
}
return true;
}
else return false;
}simply replace by :function validip($ip) {
if (filter_var($ip, FILTER_FLAG_NO_RES_RANGE)) {
return true;
} else {
return false;
}
}
If you want to filter IPv4/IPv6, you can check it with this code :
function validipv6($ipv6) {
if (filter_var($ipv6, FILTER_FLAG_IPV6, FILTER_FLAG_RES_PRIV_RANGE)) {
return true;
} else {
return false;
}
}
function validipv4($ipv4) {
if (filter_var($ipv4, FILTER_FLAG_IPV4, FILTER_FLAG_RES_PRIV_RANGE)) {
return true;
} else {
return false;
}
}Be carefull there is a little bug in PHP 5.* and PHP 6 and compatibility with ipv6 :
[url="http://bugs.php.net/bug.php?id=47435"]http://bugs.php.net/bug.php?id=47435[/url]
This is just a little hack for ip validation, but filter php function are very usefull to check integer, string, and POST/GET values...