Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

#30313 [Opn->Csd]: ip to country function
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

Report this thread to moderator Post Follow-up to this message
Old Post
goba@php.net
10-11-04 08:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Mirrors archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:47 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.