asmith Posted January 9, 2008 Share Posted January 9, 2008 how can i validate ip address coming from an input of a form ? is it ALWAYS only 4 numbers separated by 3 dots ?? Quote Link to comment https://forums.phpfreaks.com/topic/85138-solved-ip-address/ Share on other sites More sharing options...
rajivgonsalves Posted January 9, 2008 Share Posted January 9, 2008 Yes that should be it... Quote Link to comment https://forums.phpfreaks.com/topic/85138-solved-ip-address/#findComment-434355 Share on other sites More sharing options...
Daniel0 Posted January 9, 2008 Share Posted January 9, 2008 <?php $long = ip2long($ip); if($long == -1 || $long === false || long2ip($long) != $ip) { echo 'The IP is invalid'; } ?> Based of examples from: http://php.net/ip2long Quote Link to comment https://forums.phpfreaks.com/topic/85138-solved-ip-address/#findComment-434362 Share on other sites More sharing options...
asmith Posted January 9, 2008 Author Share Posted January 9, 2008 thanks a lot guys, that was what i needed. Quote Link to comment https://forums.phpfreaks.com/topic/85138-solved-ip-address/#findComment-434369 Share on other sites More sharing options...
jordanwb Posted January 12, 2008 Share Posted January 12, 2008 Keep in mind IPv6 is on the horizon so beware about that. Quote Link to comment https://forums.phpfreaks.com/topic/85138-solved-ip-address/#findComment-437383 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.