jeddi
07-09-2009, 01:22 PM
Hi,
I am testing my script to locate
the ip address from a look up file.
It seems to work OK as the script stops when it finds
the correct row - but I can not echo the final result :o
This is the script:
<?php
$ip = "1094913047";
$geo_arr = file('GeoIP_sm.csv');
for($i=0; $i<count($geo_arr); $i++) {
$arrayOfLine = explode(',', $geo_arr[$i]);
if($ip >= $arrayOfLine[0] && $ip <= $arrayOfLine[1] ) {
$countryName = $arrayOfLine[2];
return ($countryName);
}
else {
echo "<br>Searching: line $i - $arrayOfLine[0]:$arrayOfLine[1]:$arrayOfLine[2]";
}
}
echo "<BR> <B>Country: </B>".$countryName;
?>
For some reason the display stops like this:
Searching: line 11436 - 1094912248:1094912775:"United States"
Searching: line 11437 - 1094912776:1094912783:"Puerto Rico"
Searching: line 11438 - 1094912784:1094913039:"United States"
Looks like the following line contains the
number 1094913047 in its range.
But why doesn't it display it.
I must be using the return incorrectly ?
I am testing my script to locate
the ip address from a look up file.
It seems to work OK as the script stops when it finds
the correct row - but I can not echo the final result :o
This is the script:
<?php
$ip = "1094913047";
$geo_arr = file('GeoIP_sm.csv');
for($i=0; $i<count($geo_arr); $i++) {
$arrayOfLine = explode(',', $geo_arr[$i]);
if($ip >= $arrayOfLine[0] && $ip <= $arrayOfLine[1] ) {
$countryName = $arrayOfLine[2];
return ($countryName);
}
else {
echo "<br>Searching: line $i - $arrayOfLine[0]:$arrayOfLine[1]:$arrayOfLine[2]";
}
}
echo "<BR> <B>Country: </B>".$countryName;
?>
For some reason the display stops like this:
Searching: line 11436 - 1094912248:1094912775:"United States"
Searching: line 11437 - 1094912776:1094912783:"Puerto Rico"
Searching: line 11438 - 1094912784:1094913039:"United States"
Looks like the following line contains the
number 1094913047 in its range.
But why doesn't it display it.
I must be using the return incorrectly ?