BAN ip

Started on the old forum in November 2010 · view the original in the archive · old links redirect here

2 replies · 793 views · started 16 years ago · 1 min read

2 participants
wap-ruler Developer · 143 posts #1

very besic script to block a ip to ur site

1. <?php - Starts the php tag. Lets the browser know what language you are using.
2. $ip = getenv('REMOTE_ADDR'); - Gets the users IP address
3. $blocked = "xx.xx.xx.xx"; - Tells the browser that the "xx.xx.xx.xx" IP is blocked/banned
4. if (ereg($blocked,$ip)) - If the blocked/banned IP is the same as the users IP, the following echo will be displayed.
5. { - Starts a bracket
6. echo "You Have Been Banned"; - Echos the "You Have Been Banned" line onto the page.
7. exit(); - Exit so no more content is ouput
8. } - Ends a bracket
9. ?> - Ends the php tag

use thanks plz

Added after 4 minutes:

it look likes such..

<?php
$ip = getenv('REMOTE_ADDR');
$blocked = "xx.xx.xx.xx"; //chnge d ip address u want to block
if (ereg($blocked,$ip))
{
echo "You Have Been Banned";
exit();
?> 

ImPoSsIbLe iS nOthInG aS ImPoSsible ItSelF SaYs "I M POSSIBLE"

GumSlone Administrator Principal · 1,690 posts #2

I use this one:

function is_banned()
{
$banned_ip = array();
$banned_ip[] = '117.201.35.*';
$banned_ip[] = '114.31.129.*';
foreach($banned_ip as $banned)
{
$blacked=str_replace('*', '', $banned);
if (stristr($_SERVER['REMOTE_ADDR'],$blacked))
{
return true;
}
}
return false;
}

if (is_banned()) exit();

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

wap-ruler Developer · 143 posts #3

nice share br0..!!

ImPoSsIbLe iS nOthInG aS ImPoSsible ItSelF SaYs "I M POSSIBLE"

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close