At 23:04 18.03.2003, Will Bown said:
--------------------[snip]--------------------
>I am having trouble verifying if a user is within a specified I.P. range.
>The idea is that if a user is at a library within an I.P. range like
>231.55.*.* and their I.P. address is 231.55.122.226 a session would be
>registered for them. See my code below. This works but only for some I.P.'s
>in a range. 
>
>Can anyone suggest a solution or resource that can help me?
>
>$sql = "select  *  from customers where ip1 <=\"$remote_address\" and ip2
>>=\"$remote_address\"";
>$sql_result = mysql_query($sql,$connection)
> or die("Couldn't execute query. AUTO SIGN IN SELECT");
>
>while ($row = mysql_fetch_array($sql_result)) {
> $ip1 = $row["ip1"];
> $ip2 = $row["ip2"];
>   $fname = $row["fname"];
>  $lname = $row["lname"];
>  $institution = $row["institution"];
>
>$num = mysql_num_rows($sql_result);
>$sign_in="$fname $lname $institution";
>
>if($num>0){
> session_register("sign_in");
> }
>else{echo" you can't see this page"}
--------------------[snip]-------------------- 

You need to create a number out of the dotted IP string to use them in
valid <= and >= comparisons. This is a valid procedure, since the IP
basically _IS_ a number, it's just written in the dotted notation to aid us
miserable human beings.

$abytes = explode('.', $ip);         // explode the IP string
$ip = 0;
foreach ($abytes as $byte) $ip = ($ip << 8) + $byte;

This will give you the valid numeric equivalent of the IP address.


-- 
   >O     Ernest E. Vogelsinger
   (\)    ICQ #13394035
    ^     http://www.vogelsinger.at/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to