[Tut] Super Simple php IP banning
IP Banning is a method often used to stop annoying or abusive users accessing a website system such as forums or shoutbox's.
A simple way to ban users by there Ips is to use a script like this>
PHP Code:
<?php
//Array of Banned ips
$banned_ips[0] = "000.000.000.001";
$banned_ips[1] = "000.000.000.002";
$banned_ips[2] = "000.000.000.003";
$banned_ips[3] = "000.000.000.004";
$banned_ips[4] = "000.000.000.005";
$banned_ips[5] = "000.000.000.006";
// Loop Threw All the Ips.
for($K = 0; $K<sizeof($banned_ips); $K++)
{
//If an Ip matches the user ip. Stop the page from loading.
if($banned_ips[$K] == $_SERVER['REMOTE_ADDR']){
die("You have been Banned from viewing this Page.");
}
}
?>
What the above script does is use a hard coded array of Ip address's then match them against the user viewings IP address. If they match it then displays the "You have been banned from viewing this Page." message to that user, and does not display the rest of the page.
If the viewers ip is not matched, then they are allowed to view the page as they normally would.
The script needs to be placed at the top of a page to work correctly.
The Message shown to banned users can easily be edited, as can the lists of Banned Ips. If you wish to ban more than 6 ips, just add new entrys to the array following the sequence, aka the next one would be $banned_ips[6] = some ip address.
The rest of the script does require any changes.
Correctable (Forum Moderator) - Thread moved to Website Tutorials. Nice Tut