/    Sign up×
Community /Pin to ProfileBookmark

URGENT! Bann?

How do you ban someone from your site using their IP addresS?

to post a comment
Full-stack Developer

16 Comments(s)

Copy linkTweet thisAlerts:
@pyroAug 17.2003 — in PHP:

untested code
[code=php]<?PHP
if ($_SERVER["REMOTE_ADDR"] == 000.000.000.000) {
header ("Location:http://www.yourdomain.com/banned.php");
}
?>[/code]
That code must go at the very top of your page, before any content is printed.
Copy linkTweet thisAlerts:
@JonathanauthorAug 17.2003 — If I add more do I do this?

[code=php]
<?PHP
if ($_SERVER["REMOTE_ADDR"] == 000.000.000.000 || $_SERVER["REMOTE_ADDR"]== 000.000.000.001) {
header ("Location:http://www.yourdomain.com/banned.php");
}
?>
[/code]


And thanks for that speedy reply!
Copy linkTweet thisAlerts:
@pyroAug 17.2003 — Yep, looks good (except for the header, which I know is from the forums...)
Copy linkTweet thisAlerts:
@JonathanauthorAug 17.2003 — It has to be on the same line right?
Copy linkTweet thisAlerts:
@pyroAug 17.2003 — The if statement? Yes...
Copy linkTweet thisAlerts:
@JonathanauthorAug 17.2003 — Is this okay?

[code=php]
<?PHP
if ($_SERVER["REMOTE_ADDR"] == 222.222.222.222) {
header ("Location:banned.html");
}
?>
Copy linkTweet thisAlerts:
@pyroAug 17.2003 — I just thought of something. You'd better enclose the IP's you are banning in quotes. Also, for the header, you can use a relative path, but you are supposed to use an absolute path.
Copy linkTweet thisAlerts:
@PeOfEoAug 17.2003 — IP addresses change though. So you might ant to ban a range of ip addresses to keep them out for good.
Copy linkTweet thisAlerts:
@JonathanauthorAug 17.2003 — how do you bann a range of ip addresses?>
Copy linkTweet thisAlerts:
@PeOfEoAug 17.2003 — I dont know what it would look like in php but it would be something like

if remoteaddr < someip and > someip then redirect. It would just be a simple if statment with less than and greater then in it.
Copy linkTweet thisAlerts:
@pyroAug 17.2003 — To take all IPs from 000.000.000.000 to 000.000.000.999 use [code=php]if ($ip >= "000.000.000.000" && $ip <= "000.000.000.999")[/code] Note that by banning an IP block, you will potentially ban a large number of users...
Copy linkTweet thisAlerts:
@PeOfEoAug 17.2003 — But by not banning a block the user simply has to reconnect on another ip to come back. The best solution would be a timed system where an ip block is banned for several hours then is lifted, but it would require a data base that sotres the ip and I am guessing some xml or a system that logs the time then on page load it can be checked and unbanned by another user. But it would be very very complicated and involve xml with a server sid elanguage most likely.
Copy linkTweet thisAlerts:
@Robert_WellockAug 18.2003 — It may have been easier to use .htaccess to ban the IP numbers.
Copy linkTweet thisAlerts:
@Daot_LagorilleAug 18.2003 — As all my "rap artist" friends say:

"This shit is [i]tight[/i]!"

Nice bit o' the ol' "php" code there.
Copy linkTweet thisAlerts:
@PeOfEoAug 18.2003 — o...k
Copy linkTweet thisAlerts:
@pyroAug 18.2003 — Lol... glad you like it... ?
×

Success!

Help @Jonathan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...