?
Solved

Seriously urgently help needed.

Posted on 2003-10-28
16
Medium Priority
?
255 Views
Last Modified: 2006-11-17
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.


0
Comment
Question by:vince2874
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
16 Comments
 
LVL 13

Expert Comment

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

i think

cheers,

loz
0
 
LVL 13

Expert Comment

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

that's the one
0
 
LVL 11

Expert Comment

by:shmert
ID: 9635545
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.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

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

Author Comment

by:vince2874
ID: 9635565
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..
0
 

Author Comment

by:vince2874
ID: 9635592
No choice for the time been I have to ban this range of users.. if not the issus cannot be controlled
0
 
LVL 13

Expert Comment

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

that should work
0
 

Author Comment

by:vince2874
ID: 9635644
lozloz,

is not working also. I still can access the page
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9635657
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
0
 
LVL 13

Accepted Solution

by:
lozloz earned 500 total points
ID: 9635687
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;
?>
0
 

Author Comment

by:vince2874
ID: 9635702
I checked my own ip and I did not changed it.

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

Author Comment

by:vince2874
ID: 9635796
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?
0
 

Author Comment

by:vince2874
ID: 9635920
lozloz,

it works now, thanks for the help!
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9635923
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;
0
 

Author Comment

by:vince2874
ID: 9635975
lozloz,

Thanks, your previous code works!
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9636056
no probs
0

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question