Clan Adverts

www.afgserv.com

 

Simple Ip Banner

Description: This tutorial teaches you how to make a simple IP banner in PHP. 2 Examples are shown, one for a single IP, the other for multiple IPs.
Version: 1.0
Added on: 24 February 2007
Author: unknown
Difficulty Level: Very Easy
Views: 793
Detailed Profile

A banner works just like any other comparison statement, but it compares the banned ip to the user's current ip, and checks if it is in the banned list. If it is, then it disallows access to the site.

Example 1

Code:

$bannedip = "111.111.111.111";
if($_SERVER['REMOTE_ADDR'] == $bannedip){
die("You are banned!");
}


This bans the user with an ip of 111.111.111.111 and displays the message
You are banned!

Example 2
Code:

$bannedips = array("111.111.111.111,
"222.222.222.222",
"another ip",
"and another ip");
for($i=0;$i<=sizeof($bannedips);$i++){
if($bannedips[$i] == $_SERVER['REMOTE_ADDR']){die("Banned!");
}



If the IP is in the $bannedips array list, it will ban the user and display the message Banned!