PHP
  Home arrow PHP arrow Page 2 - Building an IP-to-Country Mapping Application with PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Building an IP-to-Country Mapping Application with PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2009-02-03


    Table of Contents:
  • Building an IP-to-Country Mapping Application with PHP
  • Start building an IP-to-country PHP application
  • Transferring the data of the IP-to-country database to the MySQL table
  • Importing records of the IP-to-country database to the MySQL table

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Building an IP-to-Country Mapping Application with PHP - Start building an IP-to-country PHP application
    ( Page 2 of 4 )

    Before you start learning how to build an IP-to-country application with PHP, you should download the source lookup database from the Webnet77’s web site. Then, point your browser to http://software77.net/cgi-bin/ip-country/geo-ip.pl and proceed to download the ZIP file that contains a CSV version of the database to your machine (make sure to read the corresponding term and conditions before doing this).

    Got that file uncompressed on your computer? Good. Now, it’s time to use it to transfer all the records contained in the source database to a new MySQL table, so they can be accessed with PHP. To do so, you’ll need to rename the downloaded file to “iptocountry.csv,” and then create the table in question in the following way:


    CREATE TABLE ‘iptocountry’ (

    ‘lower_bound’ INT(11) UNSIGNED NOT NULL default '0',
    ’upper_bound’ INT(11) UNSIGNED NOT NULL default '0',
    ’owner’ VARCHAR(20) NOT NULL,
    ’last_updated’ INT(11) DEFAULT NULL,
    ’two_chars_country’ CHAR(2) NOT NULL default '',
    ’three_chars_country’ CHAR(3) NOT NULL default '',
    ’country’ VARCHAR(100) NOT NULL default ''

    );


    As shown by the above SQL code, the structure of the previous MySQL “iptocountry” table is comprised of seven fields, whose names speak for themselves about the type of data that they’ll house. In this case, the two first fields will store a lower IP boundary and an upper IP boundary respectively, represented as numbers (not as dot-separated octets). Then, there are a couple of additional fields, called “owner” and “last_updated,” where the first one represents the registry that owns that range of IP addresses, and the second field, not surprisingly, is the last time the range was updated.

    In addition, the last three fields of the table will be used for storing the name of the country that corresponds to that range of IP addresses in the form of two-character and three-character strings respectively, as well as the country’s full name. Not too hard to grasp, right?

    So far, so good. At this point, you’ve created a simple MySQL table, which will store all of the data required for building an IP-to-country mapping program with PHP. It’s quite possible, however, that at this moment you’re wondering how this data will be imported to this table.

    Well, since the source lookup database is actually structured as a CSV file (comma-separated values), it’s necessary to build a simple PHP script that imports the data from that file to the “iptocountry” MySQL table.

    Thus, if you’re interested in learning the full details of how this script will be set up, please click on the link that appears below and read the section to come.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Adding Ordering and Grouping Clauses to the ...
    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek