Jump to content


Using a range of numbers vs individual code lines


  • Please log in to reply
2 replies to this topic

#1 Guest_mike93101_*

Guest_mike93101_*
  • Guests

Posted 16 September 2006 - 09:23 PM

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....untry_from.php/' ) ;
if  (  $_SERVER['REMOTE_ADDR']  ==  "68.6.37.101"  ) header( 'Location: http://www.xxxxxxxx....untry_from.php/' ) ;
if  (  $_SERVER['REMOTE_ADDR']  ==  "68.6.37.102"  ) header( 'Location: http://www.xxxxxxxx....untry_from.php/' ) ;
if  (  $_SERVER['REMOTE_ADDR']  ==  "68.6.37.103"  ) header( 'Location: http://www.xxxxxxxx....untry_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....untry_from.php/' ) ;

But it does not see the range of IP addresses.  Is this possible or do I need to type them individually?

BOB



#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 16 September 2006 - 10:20 PM

<?php

if (substr($_SERVER['REMOTE_ADDR'], 0, 7) == '68.6.37') 
     header( 'Location: http://www.mikebphoto.com/maintenance.php/' ) ;

?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 mainewoods

mainewoods
  • Members
  • PipPipPip
  • Advanced Member
  • 685 posts
  • LocationMaine

Posted 16 September 2006 - 10:22 PM

try this:
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 comparison
if ($current_ipn >= $low_ipn &&  $current_ipn <= $high_ipn)
    header("location:  ***");





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users