Jump to content

IP address limmits


otuatail

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.
Link to comment
https://forums.phpfreaks.com/topic/15236-ip-address-limmits/
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
Link to comment
https://forums.phpfreaks.com/topic/15236-ip-address-limmits/#findComment-61568
Share on other sites

Archived

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

×
×
  • Create New...

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.