php BAN system
How to create easy ip ban system with PHP?
system for ban user ip
CREATE TABLE `bans` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`ip` CHAR( 15 ) NOT NULL ,
) ENGINE = MYISAM
example template:
<div>
<form action="" method="post">
Ban IP: <input type="text" name="ip" value="***.***.***.***" /> <br />
<input type="submit" name="ban" value="ban this ip" />
</form>
</div>
php code:
<?php
if(isset($_POST['ban'])){
mysql_query("
INSERT INTO
users (ip)
VALUES
('" . $_POST['ip'] . "')
");
}
?>
function checkUserBan(){
$checkUserBan_sql = "
SELECT
*
FROM
bans
";
$checkUserBan_res = mysql_query($checkUserBan_sql);
$banIp = array();
while($checkBans = mysql_fetch_array($checkUserBan_res)){
$banIp[] = $checkBans['ip'];
}
if(in_array($_SERVER['REMOTE_ADDR'], $banIp)){
Header('Location: /bans.php');
exit;
}
}
paste function "checkUserBan();" at the top of every file on your site without bans.php