Guest mike93101 Posted September 16, 2006 Share Posted September 16, 2006 I have a bunch of lines of code in my header to block certain IP addresses from my site. (They get redirected). I have 50 typed in like this:if ( $_SERVER['REMOTE_ADDR'] == "68.6.37.100" ) header( 'Location: http://www.xxxxxxxx.com/country_from.php/' ) ;if ( $_SERVER['REMOTE_ADDR'] == "68.6.37.101" ) header( 'Location: http://www.xxxxxxxx.com/country_from.php/' ) ;if ( $_SERVER['REMOTE_ADDR'] == "68.6.37.102" ) header( 'Location: http://www.xxxxxxxx.com/country_from.php/' ) ;if ( $_SERVER['REMOTE_ADDR'] == "68.6.37.103" ) header( 'Location: http://www.xxxxxxxx.com/country_from.php/' ) ; However, this could start taking a lot of time to block several different ranges from 0 to 255. I tried using this code:if ( $_SERVER['REMOTE_ADDR'] == "68.6.37.100" - "68.6.37.103" ) header( 'Location: http://www.xxxxxxxx.com/country_from.php/' ) ;But it does not see the range of IP addresses. Is this possible or do I need to type them individually?BOB Quote Link to comment Share on other sites More sharing options...
Barand Posted September 16, 2006 Share Posted September 16, 2006 [code]<?phpif (substr($_SERVER['REMOTE_ADDR'], 0, 7) == '68.6.37') header( 'Location: http://www.mikebphoto.com/maintenance.php/' ) ;?>[/code] Quote Link to comment Share on other sites More sharing options...
mainewoods Posted September 16, 2006 Share Posted September 16, 2006 try this:[code]function convert_ip($ipn) { $ipnarray = explode('.', $ipn); //creates an array of 4 elements foreach ($ipnarray as $onevalue) { $charstring .= char($onevalue); //building a string } //should return a string with length of 4! return $charstring;}//convert ip numbers$low_ipn = convert_ip('68.6.37.100');$high_ipn = convert_ip('68.6.37.103');$current_ipn = convert_ip($_SERVER['REMOTE_ADDR']);//make comparisonif ($current_ipn >= $low_ipn && $current_ipn <= $high_ipn) header("location: ***");[/code] Quote Link to comment 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.