The forums are currently locked and only available for read only access
Marty
Siktar mot toppen
Medlem
Forum Posts: 55
Member Since:
November 1, 2002
November 1, 2002
Offline
Ja. Jag har gjort en liknande grej. Den reagerar både på IP-adresser och hostnames.
function isBanned()
{
global $REMOTE_ADDR;
global $REMOTE_HOST;
$data = file("../data/banned_ips.dat");
$c = count($data);
$ban = 0;
for ($i = 0; $i < $c; $i++)
{
$d = ereg_replace("*", "[a-zA-Z0-9.]*", trim($data[$i]));
$d = ereg_replace(".", ".", $d);
if (preg_match("/^" . $d . "$/", $REMOTE_ADDR)) { $ban = 1; }
if (preg_match("/^" . $d . "$/", $REMOTE_HOST)) { $ban = 1; }
}
return $ban;
}
Filen ../data/banned_ips.dat är en vanlig textfil där det på varje rad står ett ip eller en hostname, t.ex.
192.168.0.*
127.*
*.no
Du kanske måste konfigurera PHP med register_globals eller byta ut $REMOTE_ADDR mot $_SERVER[REMOTE_ADDR] o.s.v.
Laban2k
Nu vet jag hur man gör inlägg!
Medlem
Forum Posts: 22
Member Since:
July 30, 2001
July 30, 2001
Offline
Tackar tackar 😀
Skrev ihop en egen variant kort efter att jag postat frågan dock. Men din verkar vara bättre.
// ip == IP to compare.
// chain == Array with IP's
function ipComp($ip,$chain) {
$base = explode('.',$ip);
foreach($chain as $num => $val) {
$match = 0;
$dim = explode('.',$val);
if ($base[0] == $dim[0] || $dim[0] == '*') { $match += 1; }
if ($base[1] == $dim[1] || $dim[1] == '*') { $match += 2; }
if ($base[2] == $dim[2] || $dim[2] == '*') { $match += 4; }
if ($base[3] == $dim[3] || $dim[3] == '*') { $match += 8; }
if ($match == 15) { return TRUE; }
}
return FALSE;
}
Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1030
Currently Online:
Guest(s) 355
Currently Browsing this Page:
1 Guest(s)
1 Guest(s)
Top Posters:
Andreas Galistel: 16287
Jonas Klar: 15897
ilg@dd: 10810
Nyhet: 10607
Mind: 10550
Ctrl: 10355
Gueno: 9881
Guest: 9344
Snorch: 8881
Callister: 8468
Newest Members:
PetrbonFU PetrbonFU
Karine Bembry
Dolores Mcdaniels
Anibal McLeish
Francisca Alt
Alfie Everhart
Lester Huitt
Orlando Jorgensen
Mikki Lundgren
Dakota Kozlowski
Forum Stats:
Groups: 11
Forums: 59
Topics: 146630
Posts: 1300967
Member Stats:
Guest Posters: 2
Members: 79425
Moderators: 0
Admins: 11
Administrators: nordicadmin, Henrik Berntsson, Anton Karmehed, Carl Holmberg, Joel Oscarsson, Mikael Linnér, Mikael Schwartz, Andreas Paulsson, Nickebjrk, Mattias Pettersson, EmxL
© Simple:Press —