Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Contain certain digit script

Status
Not open for further replies.

queryguy

Programmer
Oct 10, 2003
23
SG
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! thank you.
 
It seems a shame to block a potential 65000 other users just to keep out one bad apple. I'd document the problems I'm having with this clown and narc to the nuisance's ISP.


Barring that, I'd first try to do it at the web server level. On Apache, for example, you could block a network from hitting anything on the server.


If that's not an option something like:

$remote = preg_replace ('/^(\d{1,3}\.\d{1,3}).*$/', '$1', $_SERVER['REMOTE_ADDR']);
if ($remote == '123.456')
{
.
.
.


Want the best answers? Ask the best questions: TANSTAAFL!!
 
Hi,

I tried your code and it is not working..any helps?

No choice I have to stop this range of user from access my site first. Complain to ISP take times..
 
"Barring that, I'd first try to do it at the web server level. On Apache, for example, you could block a network from hitting anything on the server."

how to do this?
 
As to your question about my sample code's not working: Again, define "now working" as you use it in this context. I can't help you get it working until I know what's going on - and "It's not working" is vague to the point of uselessness.


As to your question about configuring Apache: That's not a PHP question -- you need to ask it in the Apache forum.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
As for your code after I place on the page, I still can access it. I tried it with my own ip address.
 
You mean this?


if ($remote == '213.136')
{
header("Location: die.php");
}
 
Oh now it works, because my ip changed. Sorry for the trouble and thanks for the help.
 
Just a quick question, would substr($remote,0,7) = "213.136" be quicker than a regulr expression ?
 
The only way to get the first two octets maybe... but
Code:
if (substr($remote,0,7) == '213.136') would fail with no error
on any IP that didn't start with 213.136...

This is one of those, a dozen ways to skin a cat problems... so here's my preferred solution.

Code:
$badapple=strpos('213.136', $_SERVER['REMOTE_ADDR']);
if ($badapple == 0 && $badapple !== false) {
  die("No web site for you.");
}

-Rob
 
Yes understand the error bit, checks and validation etc. You could explode the string as well on "." as a delimiter.

no big deal really , I just got the core php with version 5 in the other day and the tuning bit says dont use regular expressions if you can avoid it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top