Reply to Re: BAN IP (second try)

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация