PHP programs to convert an IP Address into the Country Code

For many web sites, the site owners need to know where the visitors come from. We at Sun Developer Tools organization want to know where the software developers downloading Sun Studio software. We needed an utility to convert an IP address into the country code. I searched the Internet and found many commercial offerings. However I only need the core functionality and don't want to buy a commercial product with complex user interface. After studying the public PHP code from www.tellinya.com, I wrote a complete utility set of PHP programs to convert an IP address into the country code. I think my utility package has the basic functionality needed by many people and decide to share the PHP programs here. You can download the complete set of PHP programs ip2c.tar.gz here. After downloading the file, you should run gunzip and tar commands to un-archive it. The tar file package contains the following programs:

initdb.php: A php program to convert the text IP DB into mysql DB.

check.php: A php verifying program to dump all the stored records in mysql DB.

ip2c.php: A php program to convert IP address into country code from text DB. (slow version)

ip2c_db.php: A php program to convert IP address into country code from mysql DB. (fast version)

Here are the simple steps to run this program:

1. Make sure the included php.ini file in your current directory

-- It is needed to increase PHP program memory size

2. Put your input IP addresses in input.txt (one address one line)

-- See the example input.txt file

3. Run the program as: php ip2c.php [php ip2c_db.php]

4. The output will show both in screen and in output.txt file.

Enjoy using this package and let me know if you encounter any problem. If you think the package is helpful, you may find may other interesting and helpful tools at Sun Studio site.

Comments:

Are you aware of www.maxmind.com and their GeoIP services? They have libraries for PHP, Perl, Ruby, C, Java, etc...

Posted by Kevin Hutchinson on September 09, 2008 at 10:58 AM PDT #

www.maxmind.com is a GeoIP commercial product site. They charge minimum license fee $50. There are several other commercial products in the marketplace too.

As what was mentioned in my blog, I didn't want to pay and buy a commercial product for the conversion utility and the basic database set. So I wrote the utility and also learned PHP better. The trick is to get and process the geo mapping database. I think many other people have the same need and decide to share my utility and the basic database free here.

Posted by Liang Chen on September 10, 2008 at 09:52 AM PDT #

Post a Comment:
Comments are closed for this entry.
About

swdeveloper

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today