Jump to content


Photo

IP address limmits


  • Please log in to reply
2 replies to this topic

#1 otuatail

otuatail
  • Members
  • PipPipPip
  • Advanced Member
  • 960 posts

Posted 21 July 2006 - 09:48 AM

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.

#2 chrisprse

chrisprse
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts
  • LocationUnited Kingdom

Posted 21 July 2006 - 10:04 AM

How about trying:

<?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...";
}

?>

hth

#3 otuatail

otuatail
  • Members
  • PipPipPip
  • Advanced Member
  • 960 posts

Posted 21 July 2006 - 10:08 AM

If I replace the $btm $top $val with there long values it works i.e.

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users