Ban System that allows you to ban hackers, spammers or unwanted visitors from your site.
It's really simple.
Here is the HTML Structure of the Documentation (simplified):
<div id=
"wrapper"
>
<div id=
"content2"
>
<h1 class=
"btop"
><font size=
"4"
>Page Title</font></h1>
<div class=
"bbottom"
>
Text or Content here
<a href=
"#"
class=
"btn red"
>Button</a><br><br><br>
</div>
</div>
</div>
body {font-family: Verdana, sans-serif;font-size: 14px;background: url(img/background.png);}a {text-decoration: none}.clear {clear: both;padding: 0px;margin: 0px;}#wrapper {min-height: 30px;width: 880px;margin: 0 auto;padding: 10px;padding-bottom: 0px;position: relative;margin-top: 5%;position: relative;}#content {float: center;width: 650px;padding: 0px 10px 0px 0px;}.btop {background: #eee;border: 1px solid #ccc;padding: 12px;margin: 0px;font-size: 15px;color: #555;text-shadow: 0px 1px #fff;-moz-border-radius: 4px 4px 0px 0px;-webkit-border-radius: 4px 4px 0px 0px;border-radius: 4px 4px 0px 0px;-moz-box-shadow: 0px 0px 0px 1px #fff inset;-webkit-box-shadow: 0px 0px 0px 1px #fff inset;box-shadow: 0px 0px 0px 1px #fff inset;}.btop {background: #f9f9f9;/* Old browsers *//* IE9 SVG, needs conditional override of 'filter' to 'none' */background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2Y5ZjlmOSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNlZWVlZWUiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);background: -moz-linear-gradient(top, #f9f9f9 0%, #eeeeee 100%);/* FF3.6+ */background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f9f9f9), color-stop(100%,#eeeeee));/* Chrome,Safari4+ */background: -webkit-linear-gradient(top, #f9f9f9 0%,#eeeeee 100%);/* Chrome10+,Safari5.1+ */background: -o-linear-gradient(top, #f9f9f9 0%,#eeeeee 100%);/* Opera 11.10+ */background: -ms-linear-gradient(top, #f9f9f9 0%,#eeeeee 100%);/* IE10+ */background: linear-gradient(top, #f9f9f9 0%,#eeeeee 100%);/* W3C */filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f9f9f9', endColorstr='#eeeeee',GradientType=0 );/* IE6-8 */;}.bbottom {border: 1px solid #ccc;padding: 9px;border-top: 0px;-moz-border-radius: 0px 0px 4px 4px;-webkit-border-radius: 0px 0px 4px 4px;border-radius: 0px 0px 4px 4px;background: #fff;margin-bottom: 10px;}.redd {color: #e15f4f;}.btn {padding: 20px 24px 20px 24px;cursor: pointer;text-align:centertext-decoration: none;}.red {background: #e15f4f;color: #fff;text-align:centertext-decoration: none;-moz-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;-moz-box-shadow: 0px 1px 0px 0px #f99286 inset;-webkit-box-shadow: 0px 1px 0px 0px #f99286 inset;box-shadow: 0px 1px 0px 0px #f99286 inset;border: 1px solid #dd4e3e;opacity: 0.9;filter: Alpha(opacity=90);text-shadow: 0px -1px 0px #e01c06;}.red:hover {opacity: 1;filter: Alpha(opacity=1);}.red:active {position: relative;top: 1px;}#footer {width: 890px;margin: 0 auto;margin-top: -1px;text-align: right;color: #292224;margin-bottom: 30px;}
Config file - Connect with database
$server =
"localhost"
;
$username =
"root"
;
$password =
"password"
;
$db_name =
"dbname"
;
$connect = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($db_name, $connect) or die (mysql_error());
mysql_query(
"SET NAMES utf8"
);
?>
Main ban script
require
"config.php"
;
$guestip = $_SERVER[
'REMOTE_ADDR'
];
$querybanned = mysql_query(
"SELECT * FROM `bans` WHERE ip='$guestip'"
);
$banned = mysql_num_rows($querybanned);
$row = mysql_fetch_array($querybanned);
$reason = $row[
'reason'
];
if
($banned -->
"0"
){
die(
"<center><font color="
red
"><b>You are banned from the site</b></font><br>
Reason: $reason<br> <br><img src="
img/banned.png
"></center>"
);
}
else
{
echo
'
<center><font color="green"><b>You are not banned from the site</b></font><br>
<img src="img/notbanned.png" width="190px" height="300px">
</center>
'
;
}
?>
Add ban script
if
(isset($_POST[
'submit'
])){
$ip = addslashes(htmlspecialchars($_POST[
'ip'
]));
$months = array(
""
,
"January"
,
"February"
,
"March"
,
"April"
,
"May"
,
"June"
,
"July"
,
"August"
,
"September"
,
"October"
,
"November"
,
"December"
);
$date = date(
'd'
,time()).
' '
.$months[date(
'n'
,time())].
' '
.date(
'Y'
,time());
$reason = addslashes(htmlspecialchars($_POST[
'reason'
]));
$queryvalid = mysql_query(
"SELECT * FROM `bans` WHERE ip='$ip' LIMIT $redove, $broinastranica"
);
$validator = mysql_num_rows($queryvalid);
if
($ip == NULL){
echo
'
<br /--><center>Please fill the ip address input</center><br>
exit();
}
if ($reason == NULL){
echo '
<br><center>Please fill the reason input</center><br>
exit();
}
if
($validator >
"0"
){
echo
"<br><center>There is an existing ban for this IP</center><br>"
;
}
else
{
$query = mysql_query(
"INSERT INTO `bans` (ip, date, reason) VALUES('$ip', '$date', '$reason')"
);
echo
"<br><center><b>$ip</b> was successfully banned!</center><br>"
;
}
}
else
{
echo
'
<form action="" method="post">
<p>
<label>IP Address</label>
<input name="ip" type="text">
</p>
<p>
<label>Reason</label>
<input name="reason" type="text">
</p>
<br><input type="submit" class="btn red" name="submit" value="Ban">
</form>
'
;
}
?>
View bans script
$pageNum = 1;
if
(isset($_GET[
'page'
]))
{
$pageNum = $_GET[
'page'
];
}
if
(!is_numeric($pageNum)){
die (
"Error"
);
}
$redove = ($pageNum - 1) * $broinastranica;
$sql =
"SELECT * FROM bans ORDER by id DESC LIMIT $redove, $broinastranica"
;
$result = mysql_query($sql);
$count = mysql_num_rows($result);
if
($count <= 0) {
echo
'There are no bans.'
;
}
else
{
echo
'
<table cellspacing="0"-->
ID
IP Address
Date
Reason
Actions
'
;
while
($row = mysql_fetch_assoc($result)) {
echo
'
'
.$row[
'id'
].
'
'
.$row[
'ip'
].
'
'
.$row[
'date'
].
'
'
.$row[
'reason'
].
'
<a href="?delete-id='
.$row[
'id'
].
'" title="Delete"><img src="img/icons/delete_16.png" alt="Delete"> Delete</a>
'
;
}
echo
'
<center>
<br>Pages:<br>
<p class="pagerp">
'
;
$query =
"SELECT COUNT(id) AS numrows FROM bans"
;
$result = mysql_query($query) or die(
'MySQL Error'
);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row[
'numrows'
];
$maxPage = ceil($numrows/$broinastranica);
$nomeranastranici =
''
;
for
($page = 1; $page <= $maxPage; $page++)
{
if
($page == $pageNum)
{
$nomeranastranici .=
" <a href="
?page=$page
" class="
\"pager\"
">$page</a> "
;
}
else
{
$nomeranastranici .=
" <a href="
\"?page=$page\"
" class="
\"pager\"
">$page</a> "
;
}
}
if
($pageNum > 1)
{
$page = $pageNum - 1;
$predishna =
" <a href="
\"?page=$page\"
" class="
\"pager\"
">Previous</a> "
;
$parva =
" <a href="
\"?page=1\"
" class="
\"pager\"
">First</a> "
;
}
else
{
$predishna =
' '
;
$parva =
' '
;
}
if
($pageNum < $maxPage)
{
$page = $pageNum + 1;
$sledvashta =
" <a href="
\"?page=$page\"
" class="
\"pager\"
">Next</a> "
;
$posledna =
" <a href="
\"?page=$maxPage\"
" class="
\"pager\"
">Last</a> "
;
}
else
{
$sledvashta =
' '
;
$posledna =
' '
;
}
echo
""
.$parva . $predishna . $nomeranastranici . $sledvashta . $posledna;
echo
'</p></center>'
;
}
if
($_GET[
'delete-id'
]){
$id = (int)$_GET[
"delete-id"
];
$query = mysql_query(
"DELETE FROM `bans` where id='$id'"
);
echo
"<br><center>The ban was removed successfully</center><br>"
;
}
?>
Search for ban script
$
for
= $_GET[
'keywords'
];
if
($_GET[
'keywords'
])
{
$duma = $_GET[
'keywords'
];
if
(strlen($duma) < 7)
{
echo
'
Please enter at least 7 characters
'
;
}
else
{
$sql =
"SELECT * FROM bans WHERE ip LIKE '%$duma%' ORDER BY id DESC"
;
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$broi = mysql_num_rows($result);
if
($broi == 0)
{
echo
'
There are no bans
'
;
}
else
{
echo
'<p-->'
.$broi.
' results were found for your search<p></p>
'
;
echo
'
'
;
echo
' <table cellspacing="0">
<tbody><tr>
<th>ID</th>
<th>IP Address</th>
<th>Date</th>
<th>Reason</th>
<th>Actions</th>
</tr><tr class="even">
<td>'
.$row[
'id'
].
'</td>
<td>'
.$row[
'ip'
].
'</td>
<td>'
.$row[
'date'
].
'</td>
<td>'
.$row[
'reason'
].
'</td>
<td>
<a href="dashboard.php?delete-id='
.$row[
'id'
].
'" title="Delete"><img src="img/icons/delete_16.png" alt="Delete"> Delete</a>
</td>
</tr></tbody></table>'
;
}
}
}
?>
Thanks so much to