Jump to content

Archived

This topic is now archived and is closed to further replies.

Guest mike93101

Using a range of numbers vs individual code lines

Recommended Posts

Guest mike93101
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

Share this post


Link to post
Share on other sites
[code]<?php

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

?>
[/code]

Share this post


Link to post
Share on other sites
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 comparison
if ($current_ipn >= $low_ipn &&  $current_ipn <= $high_ipn)
    header("location:  ***");[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.