Forum Moderators: coopster

Message Too Old, No Replies

ban ip

         

jenjenut233

7:04 am on Nov 24, 2003 (gmt 0)



can someone please help me ban an ip address... i've tried using the following format, but for some reason it isn't working (maybe i just didn't copy it right)

<?php
$banned_ip = array();
$banned_ip[] = '111.111.111.111';
$banned_ip[] = '111.111.111.112';
$banned_ip[] = '111.111.111.113';
$banned_ip[] = '111.111.111.114';

foreach($banned_ip as $banned) {
$ip = $_SERVER['REMOTE_ADDR'];
if($ip == $banned){
echo "You have been banned!";
exit();
}
}
// rest of PHP Script here!
?>

jdMorgan

8:17 am on Nov 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jenjenut233,

Welcome to WebmasterWorld [webmasterworld.com]!

I can't answer your question, but I do want to point out two things that may help in the long run:

First, make sure your final script returns a 403-Forbidden HTTP response header to the client. If it is a robotic client, then that is all it will understand, since it won't 'read' your message.

Second, take the $ip = $_SERVER['REMOTE_ADDR']; line out of the loop and move it up. There is no reason to query the server variable list each time through the loop, and doing so will only slow things down.

Jim

hakre

10:25 am on Nov 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi jenjenut233,

i can't tell you either, but probably

$_SERVER['REMOTE_ADDR'];
isn't set. check this first, because some server configurations can lead to another var for the remote-addy.

hope that helps.