Jump to content

Archived

This topic is now archived and is closed to further replies.

otuatail

IP address limmits

Recommended Posts

Is there a full list of functions from a to z regardless of string or numeric? I spent ages writing  ip2long() it is there already.

But  this is confusing me. I am trying to test if an IP address is within a range of 2 others. I should get "IN" not "OUT"

$bl = '68.0.0.0';
$tl = '68.255.255.255';
$ip = '68.142.250.142';

// function ipband()
$btm = ip2long($bl);
$top = ip2long($tl);
$val = ip2long($ip);

$pos = "OUT";
if ($ip >= $btm && $ip <= $top)
{
  $pos = "IN";
}
// return $pos;

echo($pos . "<br><br>");


Desmond.

Share this post


Link to post
Share on other sites
How about trying:

[code=php:0]
<?php

$bl = "68.0.0.0";
$tl = "68.255.255.255";
$ip = "68.142.250.142";

$bl = str_replace('.', '', $bl);
$tl = str_replace('.', '', $tl);
$ip = str_replace('.', '', $ip);

if(($ip >= $bl) && ($ip <= $tl)) {
echo "IP is in range...";
}

else {
echo "IP is not in range...";
}

?>
[/code]

hth

Share this post


Link to post
Share on other sites
If I replace the $btm $top $val with there long values it works i.e.

if (1150220942 >= 1140850688 && 1150220942 <= 1157627903)
{
  $pos = "IN";
}

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.