note 71955 added to function.ip2long

From: Date: Tue, 26 Dec 2006 08:20:49 +0000
Subject: note 71955 added to function.ip2long
Groups: php.notes 
Request: Send a blank email to php-notes+get-120913@lists.php.net to get a copy of this message
Here's a simple IP address match checking function. It takes 3 arguments: ip address to check (after ip2long), ip address to check against (after ip2long), and mask to check against (integer 0-32). Just make sure you perform ip2long on the ip addresses before inputting them to the function. function match_ip($check_ip, $match_ip, $match_mask = 32) { for ($i = 0 ; $i < $match_mask ; $i++) { $n = pow(2, 31 - $i) ; if (($n & $check_ip) != ($n & $match_ip)) { return FALSE ; } } return TRUE ; } I've been looking for a function like this for a while, i hope it helps someone. ---- Server IP: 64.71.164.2 Probable Submitter: 208.59.165.230 ---- Manual Page -- http://www.php.net/manual/en/function.ip2long.php Edit -- https://master.php.net/note/edit/71955 Del: integrated -- https://master.php.net/note/delete/71955/integrated Del: useless -- https://master.php.net/note/delete/71955/useless Del: bad code -- https://master.php.net/note/delete/71955/bad+code Del: spam -- https://master.php.net/note/delete/71955/spam Del: non-english -- https://master.php.net/note/delete/71955/non-english Del: in docs -- https://master.php.net/note/delete/71955/in+docs Del: other reasons-- https://master.php.net/note/delete/71955 Reject -- https://master.php.net/note/reject/71955 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120913) next »