#30313 [NEW]: ip to country function
| From: | bakr_fathy at yahoo dot com | Date: | Sat, 02 Oct 2004 19:12:11 +0000 |
| Subject: | #30313 [NEW]: ip to country function | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-26306@lists.php.net to get a copy of this message | ||
From: bakr_fathy at yahoo dot com
Operating system:
PHP version: Irrelevant
PHP Bug Type: Website problem
Bug description: ip to country function
Description:
------------
I'm Bakr Alsharif from Egypt, I had to post this bug to you,
Because it's in a function called "i2c_go" which is being used in all
php.net mirrors
The file is : (./includes/ip-to-country.inc)
required files : (./backend/ip-to-country.idx) ,
(backend/ip-to-country.db)
Details :-
I was using the same function with the same files as descriped above, and
when i tried some ips to get their countries' codes
the country was "NA" while the ip is already recorded in the "db" file.
For example try the following ip : {217.144.8.107} and you sould have the
following results
so the country code should be JOR, But the function will return "NA"
Real IP = 217.144.8.107
Long IP = 3650095211
Record Number = 50661
Record Value = 36500930563650097151JOR
When I debuged the function i got the problem.
First, the function "i2c_go" uses the "idx" file to speed the search , so
it gets the start and the end
of the possible records in the "db" file by calling the
"i2c_search_in_index" function.
When using the ip in the example the start and end will be 50616 : 51254
After getting those values the "i2c_go" function calls the
"i2c_search_in_db" to start the real search in the "db" file.
that function "i2c_search_in_db" opens the "backend/ip-to-country.idx"
file and sets the file position indicator
to the starting record returned by the "i2c_search_in_index" function,
like this
fseek($ipdb, $idx[0]*24);
the "$ipdb" is the db file handler and "$idx[0]" is the index start and
"24" is number of bytes in each line.
In our case with the ip in the example it will set the file pointer to the
END OF LINE "50661"
So when we use "fread" we will read from line "50662" NOT line "50661"
and
that will make us never find the right record
because we has just skipped it. So we land on "NA" instead of "JOR".
To Solve this problem , we should set the file pointer to the END of line
"50660" so we can search from line "50661"
which returned from the i2c_search_in_index function.
The "fseek" code line should be
fseek($ipdb, ($idx[0]-1)*24);
I hope everything was clear.
Thanks for your time,
Bakr Alsharif
http://systurn.com
bakr_fathy@yahoo.com
++20127809973
--
Edit bug report at http://bugs.php.net/?id=30313&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30313&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30313&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30313&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=30313&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=30313&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=30313&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=30313&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=30313&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=30313&r=support
Expected behavior: http://bugs.php.net/fix.php?id=30313&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=30313&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=30313&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=30313&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30313&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=30313&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=30313&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=30313&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=30313&r=float
MySQL Configuration Error: http://bugs.php.net/fix.php?id=30313&r=mysqlcfg