note 54953 added to function.ip2long

From: Date: Wed, 20 Jul 2005 16:37:25 +0000
Subject: note 54953 added to function.ip2long
Groups: php.notes 
Request: Send a blank email to php-notes+get-92219@lists.php.net to get a copy of this message
A simple function to compare two IP addresses against a netmask. Useful if you're locking down a web app with an IP address, but can't force the IPs to be exactly the same. function ipcompare ($ip1, $ip2, $mask) { $masked1 = ip2long($ip1) & ip2long($mask); // bitwise AND of $ip1 with the mask $masked2 = ip2long($ip2) & ip2long($mask); // bitwise AND of $ip2 with the mask if ($masked1 == $masked2) return true; else return false; } Examples: ipcompare("192.168.1.63","192.168.1.65","255.255.255.0") // true ipcompare("192.168.1.63","192.168.1.65","255.255.255.192") // false ---- Manual Page -- http://www.php.net/manual/en/function.ip2long.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54953 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54953&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54953&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54953&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54953&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54953&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54953&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54953&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92219) next »