Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
[HACK] New function validip
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / v2.08 / v2 Only Mods Complete

Unknown User
2009-04-30 08:10:15
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 :

// 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...
Unknown User
2009-04-30 18:41:27
i can change in announce too?

look code in announce:

function validip($ip)

{

if (!empty($ip) && ip2long($ip)!=-1)

{

$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;

}
Unknown User
2009-04-30 18:52:24
so this wont work in in php 4 ?
Unknown User
2009-05-06 01:33:22
"djhowarth, post: 57127":
so this wont work in in php 4 ?
I don't think so, but you can install PECL FILTER manually.
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 1
  • Members: 0
  • Guests online: 1
  • Comments: 3
  • Messages: 1,728