ich bin gerade über folgendes IP Banning Script gestolpert:
für die Datenbank
Code
CREATE TABLE `banned` ( `id` int(11) NOT NULL auto_increment, `ip` varchar(255) NOT NULL default '', `time` varchar(255) NOT NULL default '', `long` varchar(255) NOT NULL default '', `reason` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM;
Code für die config.php Datei:
PHP Code
<?php // config $config['host'] = "localhost"; // host name of your mysql server $config['user'] = "username"; // your mysql username $config['pass'] = "password"; // your mysql password $config['db'] = "database"; // the database your table is in.
// the @ sign is an error supressor, meaning we can use our own error messages, this connects and selects db @mysql_connect("$config[host]","$config[user]","$config[pass]") or die("There was an error connecting to the database, MySql said:<br />".mysql_error().""); @mysql_select_db("$config[db]") or die("There was an error connecting to the database, MySql said:<br />".mysql_error().""); ?>
Script für die Funktionen
PHP Code
<?php // func.ban.php // checks the ip to see if it is banned function checkban($ip) { // querys database $q = mysql_query("SELECT * FROM `banned` WHERE `ip` = '$ip' LIMIT 1"); $get = mysql_num_rows($q); // if found if ($get == "1") { // deny user access $r=mysql_fetch_array($q); die("You have been banned from this website until $r[legnth]. If you feel this is in error, please contact the webmaster."); } } // places a ban in the database function addban($ip,$reason,$legnth) { // get current time $time = time(); // inserts code into database $insert = mysql_query("INSERT INTO `banned` (`ip`,`time`,`long`,`reason`) VALUES ('$ip', '$time', '$legnth', '$reason')") or die("Could not add ban.<br />".mysql.error().""); echo "The ip address, $ip, has been added to the ban list."; } // deletes a ban from the database function delban($id) { // runs a delete query $delete = mysql_query("DELETE FROM `banned` WHERE `id` = '$id' LIMIT 1") or die("Could not remove ban.<br />".mysql.error().""); echo "The ip address has been removed from the ban list."; } // lists the bans in the ban admin function listbans() { // link to add ban echo "<a href='banadmin.php?x=add'>Add Ban</a><p>"; // loop to show all band $query = mysql_query("SELECT * FROM `banned` ORDER BY time DESC"); $num = mysql_num_rows($query); if ($num) { while ($r=mysql_fetch_array($query)) { echo "$r[ip] - $r[reason] - <a href='banadmin.php?x=delete&id=$r[id]'>Delete</a><br />"; } } } ?>
und hier die Datei zum konfigurieren im Adminpanel banadmin.php (bitte unbedingt in einem sicheren Ordner abspeichern!)
PHP Code
<?php // banadmin.php
// include the files include "config.php"; include "func.ban.php"; // switch statement to do pages in admin switch ($_GET['x']) { // if no page show bans default: listbans(); break; // if add ban, show the form case "add": // if posted, insert it if ($_POST['add']) { $ip = $_POST['ip']; if (!$ip) { echo "You must put an ip address at least"; } addban($ip,$_POST[reason],$_POST[legnth]); } // otherwise show form else { echo "Add a ban.<br />"; echo "<form method='post' action='banadmin.php?x=add'>"; echo "IP Address<br /><input type='text' name='ip'><br />"; echo "Reason<br /><input type='text' name='reason'><br />"; echo "Legnth<br /><input type='text' name='legnth'><br />"; echo "<input type='submit' name='add' value='Add Ban'>"; } break; // delete ban case "delete": // got the id, preform the action if ($_GET['id']) { delban($_GET['id']); } // show error else { echo "No ip selected to remove"; } break; } ?>
folgender Code am Anfang jeder Deiner Seite prüft nun ob die IP eventuell gebannt ist:
Code
<? include "config.php"; include "func.ban.php"; checkban($_SERVER['REMOTE_ADDR']); ?>
Greetz Lp
Um auf dieses Thema zu ANTWORTEN bitte erst » hier kostenlos registrieren!!
ich bin gerade über folgendes IP Banning Script gestolpert:
für die Datenbank
Code
Code für die config.php Datei:PHP Code
Script für die FunktionenPHP Code
und hier die Datei zum konfigurieren im Adminpanel banadmin.php (bitte unbedingt in einem sicheren Ordner abspeichern!)PHP Code
folgender Code am Anfang jeder Deiner Seite prüft nun ob die IP eventuell gebannt ist:Code
Greetz Lp