Seriously urgently help needed.

vince2874
vince2874 used Ask the Experts™
on
Need urgent assistant here please.

I need to block an IP address which contains 213.136 (213.136.110.134) the first six digit from signing up my site because this user has been causing a nuisance, I blocked his IP adress but make not use because this user is not using static IP address.. but the first 6 digit is the same no change.


Can someone write me a simple script that if the remote ip contain the first 6 digit, that prevent it from proceed?

I just need something like:

if($REMOTE_ADDR=="213.136 //or how I don't know not"){

  echo "YOU ARE BLOCKED PERMANENTLY!";

}

Or someone have better ideals?



HELP please! My members are complaining.. thank you.


Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
$addr = substr($_SERVER["REMOTE_ADDR"], 7);
if($addr == "213.136") {
  die("YOU ARE BLOCKED PERMANENTLY!");
}

i think

cheers,

loz

Commented:
$addr = substr($_ENV["REMOTE_ADDR"], 7);
if($addr == "213.136") {
  die("YOU ARE BLOCKED PERMANENTLY!");
}

that's the one

Commented:
Keep in mind that this could very well block legitimate users also.  Those 6 digits encompass a large range of IP addresses.  Requiring some sort of email verification for logging in is a good way to prevent this kind of stuff from happening.  Sorry you're having this kind of trouble, sounds miserable.
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Author

Commented:
Hi.. I tried it blocking my own ip address, with the first 6 digits or the full ip address it cannot work, any helps?

Author

Commented:
shmert,

yes... is really miserable having this kind of issues... I really don;t know what to do now..email verification also can't really help because they are using free email account from yahoo, hotmail..

Author

Commented:
No choice for the time been I have to ban this range of users.. if not the issus cannot be controlled

Commented:
<?
$ip = getenv("REMOTE_ADDR");
$addr = substr($ip, 7);
if($addr == "213.136") {
  die("YOU ARE BLOCKED PERMANENTLY!");
}
?>

that should work

Author

Commented:
lozloz,

is not working also. I still can access the page

Commented:
did you change the ip to your own?

do a test by simply doing

<?
$ip = getenv("REMOTE_ADDR");
print $ip;
?>

to see if your ip is being given.. if this bit works then the rest of it should do
Commented:
if not, try this:

<?
function GetIP()
{
    if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
            $ip = getenv("HTTP_CLIENT_IP");
        else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
            $ip = getenv("HTTP_X_FORWARDED_FOR");
        else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
            $ip = getenv("REMOTE_ADDR");
        else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
            $ip = $_SERVER['REMOTE_ADDR'];
        else
            $ip = "unknown";
    return($ip);
}/*-------GetIP()-------*/
$ip = GetIP();
$addr = substr($ip, 7);
if($addr == "213.136") {
  die("YOU ARE BLOCKED PERMANENTLY!");
}
print $ip;
?>

Author

Commented:
I checked my own ip and I did not changed it.

Ok I tested the other code now give me a sec thanks

Author

Commented:
strange why now I can't block my full ip address?

I tested with the print $ip adddress and do it this way

f($REMOTE_ADDR == "xxx.xxx.x.xx") {
die("YOU ARE BLOCKED PERMANENTLY!");
}

can't work also.. what went wrong?

Author

Commented:
lozloz,

it works now, thanks for the help!

Commented:
i dont understand.. do you want to block your own ip address with my script? if you do, you want to get rid of the substr function which cuts it down to the first 6 digits so it should be:

$ip = GetIP();
$addr = $ip;
if($addr == "xxx.xxx.x.xx") {
  die("YOU ARE BLOCKED PERMANENTLY!");
}
print $ip;

Author

Commented:
lozloz,

Thanks, your previous code works!

Commented:
no probs

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial