Posted: Tue Apr 19, 2011 12:08 am
regular expression is the way 
dal 2003, semper fidelis!
https://www.goiclan.it/forum/
Code: Select all
<?php
$blacklist = array(
"/93./",
"/94.36.15.13/",
"/81.22.34.12/"
);
$client = $_SERVER['REMOTE_ADDR'];
foreach($blacklist as $ip) {
if(preg_match($ip, $client)) {
header("location: http://www.google.com/");
exit();
}
}
?>
<html>
<body>
<p>Ipnonbannato</p>
</html>
</body>Si ineffetti il codice andrebbe potenziato... l'idea però era quella...Sarn0! wrote:Errato
$deny = array("93.0.0.0", "1.2.3.4", "3.0.0.0", "10.0.0.0");
Corretto
$deny = array("93.0.0.0", "1.2.3.4", "3.0.0.0", "10.0.0");
in pratica la funzione di genny dice "prendi tutti quelli che contengono questo '10.0.0' " quindi 10.0.0.0 - 10.0.0.1 - 10.0.0.2 - 10.0.0.3 ecc....anche se, però, erroneamente prenderebbe pure 0.10.0.0 - 1.10.0.0 - 2.10.0.0 ecc....
Molto più banalmente io mi creerei un .htaccess con le subnet/ip che vuoi bannare(soluzione al quanto easy ma comunque professionale)Genny, fosse per me la implementerei lato rete la gestione delle blacklist, ma per quel che mi serve
basta e avanza il ciclo (if o for che sia)
Code: Select all
order allow,deny
deny from 1.2.3.4
deny from 1.2
deny from 1.2/16
allow from allCode: Select all
<?php
$blacklist = array(
"/93./",
"/94.36.15.13/",
"/81.22.34.12/"
);
$client = $_SERVER['REMOTE_ADDR'];
foreach($blacklist as $ip) {
if(preg_match($ip, $client)) {
header("location: http://www.google.com/");
exit();
}
}
?>
<html>
<body>
<p>Ipnonbannato</p>
</html>
</body>Grande.snipershady wrote: Come ho fatto ora, VA
la funzione preg_match
sembra fare al mio caso
http://it.php.net/manual/en/function.preg-match.php
Code: Select all
if(strlen(stristr($client,$ip))>0)Code: Select all
<Files prova.php>
order allow,deny
deny from 1.2.3.4
deny from 1.2
deny from 1.2/16
allow from all
</Files>