Redirect IP-ranges

Simple snippet for redirecting ip-ranges.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$aMyIPRange[] = '127.0.0.3/127.0.0.3';
$aMyIPRange[] = '127.0.0.0/127.0.0.10';
redirectIpRanges($aMyIPRange'http://heise.de/');
                       
function redirectIpRanges($aIPRange$sDestination)
{
    foreach((array) $aIPRange as $sRange)
    {
        $aIPRange = explode('/'$sRange);
        $iStart   = ip2long($aIPRange[0]);
        $iEnd     = ip2long($aIPRange[1]);
        $iIP      = ip2long($_SERVER['REMOTE_ADDR']);
       
        if ($iIP >= $iStart && $iIP <= $iEnd)
        header('Location: '.$sDestination);
    }
}
X

Url: http://sklueh.de/2013/09/php-verschiedene-ip-ranges-umleiten/

Language: PHP | User: sklueh | Created: Sep 16, 2013 | Tags: ip ranges redirect