Jonthefisherman
New Member
- Messages
- 64
- Reaction score
- 0
- Points
- 0
PHP:
Ban an IP from you're webpage.[/b]
[B]Create a file called banned.php containing this: [/B]
[QUOTE]
<?php
$ip = getenv('REMOTE_ADDR');
$email = "email@server.com"
$ban1 = "000.000.000"
$ban2 = "000.000.000"
$ban3 = "000.000.000"
$ban4 = "000.000.000"
$ban5 = "000.000.000"
$ban6 = "000.000.000"
if($ip == $ban1 || $ip == $ban2 || $ip == $ban3 || $ip == $ban4 || $ip == $ban5 || $ip == $ban6)
{
echo "You have been banned from this website. To appeal this ban, contact the webmaster at $email."
exit;
}
?> [/QUOTE]
Replace the 0's with the IP address you want to ban.
[B]Add the this code to all the pages on you're site you want this to apply to.[/B]
( Make sure the file extension of the page is .PHP | Example = index.php )
[QUOTE] <?PHP
include("banned.php");
?> [/QUOTE]
[B]The code should now work, now to explain the code:[/B]
[QUOTE]
[I] $ip = getenv('REMOTE_ADDR');[/I] - I am assigning the person's IP to the variable $ip. $ip is used when checking the IP against the banned list.
[I] $email = "email@server.com" [/I] - Change [EMAIL="email@server.com"]email@server.com[/EMAIL] to your e mail so people can contact you regarding the ban.
[I] $ban1 = "000.000.000" [/I] - Change the 0's to the person's IP you wamt to ban. That assigns the banned IP to the variable. It is the same with ban1 to 6
[I] if($ip == $ban1 || $ip == $ban2 || $ip == $ban3 || $ip == $ban4 || $ip == $ban5 || $ip == $ban6) [/I] - Checks the $ip variable against a list of banned ip's. If it matches, it echos and the user cannot view the site. However, if it does not match any IP on the list of banned IP addresses the user can view the webpage normally.
If you want to ban anymore IP's, add another line to the banned list. (Remember to change the number)
Then, edit the if statement.
[/QUOTE]
Last edited: