Closed Thread Icon

Topic awaiting preservation: allowing a range of ip addresses (PHP) (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=12250" title="Pages that link to Topic awaiting preservation: allowing a range of ip addresses (PHP) (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: allowing a range of ip addresses (PHP) <span class="small">(Page 1 of 1)</span>\

 
RypTide
Nervous Wreck (II) Inmate

From: Manassas VA, USA
Insane since: May 2002

posted posted 06-06-2002 09:20

Hello again all.

Anyone have a good way of testing if the $REMOTE_ADDR is in a certain range? and performing some action if it is?

something with the ereg() function maybe? I was thinking along this line, but I can't seem to find the magic pattern to match

This would be for a portal which will have tailored content to those with certain ip addresses.

Ideas? I searched the forums, but I did't see anything.

RypTide

"Music is the vernacular of the human soul" ~ Geoffrey Latham

Sash
Paranoid (IV) Inmate

From: Canada, Toronto
Insane since: May 2000

posted posted 06-06-2002 17:17

Before you try PHP, have you given any thought about using .htaccess solution. I think it is a file that should solve your problem.

Sasha »

RypTide
Nervous Wreck (II) Inmate

From: Manassas VA, USA
Insane since: May 2002

posted posted 06-06-2002 21:56

I was under the impression that .htaccess would allow/deny, but not redirect based on ip.

My understanding of the redirect was that you could have

Redirect page1.htm page2.htm

can you set a different DirectoryIndex for a block of IPs?

RypTide

"Music is the vernacular of the human soul" ~ Geoffrey Latham

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 06-06-2002 23:26

You can do that with a little help from mod_rewrite...


lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 06-07-2002 10:24

<?
$pat = '([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)';
$ip = '192.168.0.13'; // you may use $REMOTE_ADDR
echo "pt=$pat\n";
echo "ip=$ip\n";
if (ereg($pat, $ip, $results))
{
echo "class A={$results[1]}\nclass B={$results[2]}\n...";
// put here any code you like to validate the IP addr. parts
}

?>

hope it helps...

RypTide
Nervous Wreck (II) Inmate

From: Manassas VA, USA
Insane since: May 2002

posted posted 06-07-2002 22:27

That pattern works in general to make sure the ip is in the right general format (000.000.000.000), and i can check the individual parts, but....

what is the qualifier to do an exact match of a particular sub pattern, as in the exact nubmer 255, or 33 or whatever?

I need to check for an ip like this:

xxx.xxx.128.0

thru

xxx.xxx.143.255

where the xxx.xxx part is always the same. so i just need to check the third section to see if it is between 128 and 143, but I don't know how to do that, or an exact match of a particular number (not the [0-9] which is ANY number.)

RypTide

"Music is the vernacular of the human soul" ~ Geoffrey Latham

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 06-07-2002 23:13

Regular expression that Lallous posted above will split specified IP address and store the results in $results array which you can use to check if IP address is in the spcified range...

In his example $results array will contain:

$results[0] = '192.168.0.13';
$results[1] = '192';
$results[2] = '168';
$results[3] = '0';
$results[4] = '13';

And you can use simple if statement to check whether IP is in range or not...


RypTide
Nervous Wreck (II) Inmate

From: Manassas VA, USA
Insane since: May 2002

posted posted 06-08-2002 09:33

I know I can use a simple if statement to get what i need.

I wanted to know how to do it at the pattern itself, as in a pattern that will match 3 exact subpatterns, 3 digits each, and one which will look for a 3 digit number between 128 and 143

like this:

^192\.168\.([128-143]+)\.([0-255]+)$ // i know this wouldn't work.

if something like that isn't possible, that's fine, the if statements worked for what i needed, i just wondered if this was possible with pattern matching.

RypTide

"Music is the vernacular of the human soul" ~ Geoffrey Latham

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 06-08-2002 14:55

Just stick with if statements. Regular expressions don't support number ranges (as you already know), and therefore constructing regex that will match certain range of number would be a little bit tricky (you would need to use a lot of alternative patterns - "

RypTide
Nervous Wreck (II) Inmate

From: Manassas VA, USA
Insane since: May 2002

posted posted 06-09-2002 03:39

Makes sense. Thanks much.

RypTide

"Music is the vernacular of the human soul" ~ Geoffrey Latham

« BackwardsOnwards »

Show Forum Drop Down Menu