for the search, my way to preload images! haha

Search for in

Banning IPs

PHP Coding Tutorials | Submited May 18, 2008

Written by: Mr. Εv¡l

This explains how to ban an IP address with PHP. It's a decent alternative to using .htaccess..

Notes


Some douche was spamming my guestbook, so I threw this together real quick.
.htaccess is probably more efficient, but this was more convenient at the time, and it works pretty well.
I'll start off by giving you the code since the explanation is minimal.

Code


<?php

$asshat[0] = '24.253.61.96'; // The variable for the banned IPs, you can add more, but increment by one each time

if (in_array($_SERVER['REMOTE_ADDR'],$asshat))
{
header("Location: http://google.com"); // Where the banned person will end up
}

?>


Explanation:




$asshat[0] = '24.253.61.96';


$asshat is the variable, it's also an array.
You can duplicate that line to block more IPs, just increment the number by one.
24.253.61.96 is the IP I banned. You, of course, would have to put in the one you want to ban.

if (in_array($_SERVER['REMOTE_ADDR'], $asshat))


This checks if the person visiting the page has an IP that matches the one(s) in the array.

header("Location: http://google.com");


If it does then they'll be redirected to Google. That's what the header('Location: function does... It redirects >_>

tags Tags: ban IP address

3Thumbs up  Thumbs down0

Related Tutorials
Creating "Your IP is" images
Banning IPs
2 Comments
  Mr. Εv¡l ~ 06/22/08, 5:23pm
Picture..
No. This is for websites.

Report whoever is spamming your group to MySpace.
  User Picture.. ~ 06/22/08, 5:20pm
Picture..
so will this work on people that come in groups..when my group is private and hidden..but somehow he still gets in and posts perverted things..will this work for that?

1 


Sorry, you have to be a member to comment tutorials