|
Posted by Erwin Moller on 05/22/06 12:48
John wrote:
> Say I want to ban all IPs in the range 123.123 X X from access to some
> areas on my server. BUT at the same time allow just ONE of the IPs which
> relies in this IP-range, for example: 123.123.123.12
>
> Is that possible through PHP? I don't want to mess up with .htaccess files
> and so on.
>
> Code?
Hi,
Why not approach this with plain strings?
$ip = SERVER['REMOTE_ADDR'];
$allowIP = array('123.123.123.12' , '123.123.123.115');
$passOK = 'Y';
if (substr($ip,0,7) == '123.123'){
// not welcome, unless in $allowIP
if (in_array($ip,$allowIP)){
$passOK = 'Y';
} else {
$passOK = 'N';
}
}
If you need more complex fitting of IP-addresses than just simple
'startstring-fitting', you'll need more complex code of course.
Regards,
Erwin Moller
[Back to original message]
|