jackr1909 Posted December 19, 2011 Share Posted December 19, 2011 Hi, i have this code print get_domain("http://www.somedomain.com"); function get_domain($url) { $pieces = parse_url($url); $domain = isset($pieces['host']) ? $pieces['host'] : ''; if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) { return $regs['domain']; } return false; } mysql_query("INSERT INTO table VALUES('', '$domain')"); And i want to check that the www.somedomain.com is not an ipaddress or localhost (i.e. localhost, 127.*.*.*, - Local 192.168.*.* -LAN or *.*.*.* (as an ip) - Actual IP Any help would be much appreciated thanks, jack Quote Link to comment https://forums.phpfreaks.com/topic/253466-check-that-the-host-name-is-not-an-ip-address/ Share on other sites More sharing options...
The Little Guy Posted December 19, 2011 Share Posted December 19, 2011 ip2long should help you with what your looking for. <?php $ip = $_SERVER['SERVER_NAME']; var_dump(ip2long($ip)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/253466-check-that-the-host-name-is-not-an-ip-address/#findComment-1299356 Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 if (preg_match( '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/', $domain)) { This what you want? Quote Link to comment https://forums.phpfreaks.com/topic/253466-check-that-the-host-name-is-not-an-ip-address/#findComment-1299358 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.