For Programmers: Free Programming Magazines  


Home > Archive > PHP Mirrors > October 2004 > #30313 [Opn->Csd]: ip to country function









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author #30313 [Opn->Csd]: ip to country function
goba@php.net

2004-10-11, 3:56 pm

ID: 30313
Updated by: goba@php.net
Reported By: bakr_fathy at yahoo dot com
-Status: Open
+Status: Closed
Bug Type: Website problem
PHP Version: Irrelevant
New Comment:

I have committed a modified version of your patch to CVS.


Previous Comments:
------------------------------------------------------------------------

[2004-10-03 21:49:51] bakr_fathy at yahoo dot com

Sorry, but function "i2c_search_in_db"
opens the "backend/ip-to-country.db" file
NOT "backend/ip-to-country.idx".

------------------------------------------------------------------------

[2004-10-02 21:12:04] bakr_fathy at yahoo dot com

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

fs($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 "fs" code line should be
fs($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 this bug report at http://bugs.php.net/?id=30313&edit=1
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com