note 81030 modified in function.ip2long by danbrown

From: Date: Fri, 05 Dec 2008 13:30:52 +0000
Subject: note 81030 modified in function.ip2long by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147684@lists.php.net to get a copy of this message
Just a little function to check visitor's ip if it is in given range or not (I couldn't find anywhere so i improvise): <?php function in_ip_range($ip_one, $ip_two=false){ if($ip_two===false){ if($ip_one==$_SERVER['REMOTE_ADDR']){ $ip=true; }else{ $ip=false; } }else{ if(ip2long($ip_one)<=ip2long($_SERVER['REMOTE_ADDR']) && ip2long($ip_two)>=ip2long($_SERVER['REMOTE_ADDR'])){ $ip=true; }else{ $ip=false; } } return $ip; } //usage echo in_ip_range('192.168.0.0','192.168.1.254'); ?> --was-- Just a little function to check visitor's ip if it is in given range or not (I could'nt find anywhere so i improvise): function in_ip_range($ip_one, $ip_two=false){ if($ip_two===false){ if($ip_one==$_SERVER['REMOTE_ADDR']){ $ip=true; }else{ $ip=false; } }else{ if(ip2long($ip_one)<=ip2long($_SERVER['REMOTE_ADDR']) && ip2long($ip_two)>=ip2long($_SERVER['REMOTE_ADDR'])){ $ip=true; }else{ $ip=false; } } return $ip; } //usage echo in_ip_range('192.168.0.0','192.168.1.254'); http://php.net/manual/en/function.ip2long.php

« previous php.notes (#147684) next »