Thank you for the script, but it is not clear for me :-) i'm a beginner in
PHP !
This script accept all range IP for every domain, but me i need to determine
only a range IP for select domains.

Users will be connect by my network, so they have an IP give by the network.

Example (because i don't speak english very well !) :

there are 3 networks, each of them have a mask : (it is not necessary to
know these parameters i think !)
198.143.15.255 (255.255.255.0)
202.139.84.255 (255.255.255.128)
210.176.142.255 (255.255.255.192)

When a user will connect, his IP will be between 198.143.15.0 and
198.143.15.255 or between 202.139.84.0 and 202.139.84.255 or between
210.176.142.0 and 210.176.142.255

So if someone else connect without using my network, the system disallow him
and redirect in 403 Page.

To resume :
- Users will be accept by the system if they will use my network.
- Others will be redirect in 403 Page.
- So i must check there IP Addresses and authorize them or not to enter in
the member area in fontion of there IP !

Thanks for every solutions !

Byebye @+

Anthony.

> --------------------[snip]--------------------
> >well i have a problem, i try make an authentication per range IP Address
> >like :
> >from 194.195.196.0 to 194.195.196.255 but it doesn't work, except if i
make
> >an authentication for only one IP Address. I tried to make with "LOOP"
and
> >"WHILE" tag, but i got the problem everytime !
> >
> >This is the last example script i made with two domains which accept only
> >the range IP Address for each :
> >
> ><?php
> >
> >$host = getenv("REMOTE_ADDR");
> >$ip = range(0,255);
> >if ($host != "194.195.196.($ip))
> >if ($host != "195.196.197.($ip))
> --------------------[snip]--------------------
>
> Salut Anthony,
>
> you may check if an address is within a certain network/subnet, you need
to
> compare each octet.
>
> For example:
> Address 192.168.11.212  Network 192.168.12.255  Mask 255.255.255.0
> 192 & 255 = 192         192 & 255 = 192         OK
> 168 & 255 = 168         168 & 255 = 168         OK
> 11  & 255 = 11          12  & 255 = 12          NOT WITHIN SUBNET
>
> I've put this together in this littel test form:
>
> --------------------[snip]--------------------
> <?php
>
> function contains_ip($network, $snmask, $address)
> {
>         if (!is_array($network)) $network = explode(".", $network);
>         if (!is_array($snmask))  $snmask  = explode(".", $snmask);
>         if (!is_array($address)) $address = explode(".", $address);
>
>         for ($i=0; $i<4; ++$i) {
>                 $a = $address[$i]*1;
>                 $m = $snmask[$i]*1;
>                 $n = $network[$i]*1;
>                 $m1 = $a & $m;
>                 $m2 = $n & $m;
>                 if (($a & $m)  != ($n & $m))
>                         return false;
>         }
>         return true;
> }
>
> if ($network && $subnet && $address)
>         $result = contains_ip($network, $subnet, $address);
>
> ?>
>
> <html>
> <body>
> <?php if (isset($result)):?>
> <h4><?=$address?> is<?php if(!$result):?> <i>not</i><?php endif;?>
> contained in <?=$network?>, mask <?=$subnet?></h4>
> <?php endif;?>
> <form>
> Enter Address: <input type="text" name="address"
value="<?=$address?>"><br>
> Enter Network: <input type="text" name="network"
value="<?=$network?>"><br>
> Enter Subnetmask: <input type="text" name="subnet"
value="<?=$subnet?>"><br>
> <input type="submit">
> </form>
> </body>
> </html>
> --------------------[snip]--------------------


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to