Salve mi sto costruendo uno script per bloccare le ip in un sito, insomma per bannare gli utenti maleintenzionati.
Lo script che ho trovato in rete utilizza un file di testo come lista delle ip bannate ma io lo voglio tramite database:
beh ecco quà lo script trovato in rete:
<?php
$_EMAIL="******.com@******.com";
$ip = $_SERVER['REMOTE_ADDR'];
$browser = $_SERVER["HTTP_USER_AGENT"];
$tempo = getdate();
$giorno = $tempo['mday'];
$mese = $tempo['month'];
$anno = $tempo['year'];
$ore = $tempo['hours'];
$minuti = $tempo['minutes'];
$secondi = $tempo['seconds'];
$proxies = file ('ips.txt');
$_SORRY="<div align=center>
<img src=http://www.******/immagini/banned.jpg alt=You are Banned! width=400 height=400></p>
<p class=bannedtext>Sorry, but your IP adress ($ip) is currently blocked for security reasons by the Administrator.
For more informations, contact the management at: <a href=mailto:******.com@******.com>******.com@***** *.com
</a>Thanks.</p>
";
while(list($key,$val) = each($proxies)) {
if($ip == trim($val)) {
echo "$_SORRY";
mail("$_EMAIL","Blocco delle IP SmE","L'utente bannato precedentemente ed avente indirizzo IP $ip
si è collegato al sito ******.com con il browser: $browser
In data: $giorno/$mese/$anno Alle ore: $ore:$minuti:$secondi","From:$_EMAIL\r\n");
die();
}
}
?>
Io ho cercato di modificarlo nel mio piccolo ma senza successo:
<?php
$connessione = mysql_connect("sql.******.com","******","******")
or
die("Connection imposible, please check your permissions");
mysql_select_db("******",$connessione);
$ip = $_SERVER['REMOTE_ADDR'];
$browser = $_SERVER["HTTP_USER_AGENT"];
$tempo = getdate();
$giorno = $tempo['mday'];
$mese = $tempo['month'];
$anno = $tempo['year'];
$ore = $tempo['hours'];
$minuti = $tempo['minutes'];
$secondi = $tempo['seconds'];
$query = "SELECT * FROM banning WHERE ip";
$_SORRY="<div align=center>
<img src=http://www.******/immagini/banned.jpg alt=You are Banned! width=400 height=400></p>
<p class=bannedtext>Sorry, but your IP adress ($ip) is currently blocked for security reasons by the Administrator.
For more informations, contact the management at: <a href=mailto:******.com@******.com>******.com@***** *.com
</a>Thanks.</p>
";
if(in_array($ip,$query))
echo "$_SORRY";
?>
?>
Come notate oltre ad aver censurato alcune cose con ****** ho eliminato anche la funzione di invio email che era solo na scocciatura.