In case you haven't had the chance to read the preceding article of this series, in the next few lines I'm going to list for you all of the source files required for building an IP-to-country MySQL table. I will be using the records of the source lookup database, previously downloaded from Webnet77's web site.
That being said, here are the corresponding definitions for each of these files:
(definition of 'create_ip_to_country_table.sql' file)
CREATE TABLE 'iptocountry' (
'lower_bound' INT(11) UNSIGNED NOT NULL default '0',
(definition of 'populate_table.php' file)
// connect to MySQL server
throw new Exception ('Error connecting to the server.');
// select database
throw new Exception ('Error selecting database.');
// set timeout limit (handy when working with slower machines)
// open 'iptocountry.csv' file for further reading
throw new Exception ('Error reading source file.');
// read file and populate 'iptocountry' MySQL table with each line of file
// check to see if current line is not a comment
// explode values
// build query
$sql="INSERT INTO iptocountry VALUES ('".implode("','",$values)."')";
// run query against MySQL table
The two files listed above contain all the source code required for creating an IP-to-country mapping MySQL table. In this case, the first SQL file is responsible for creating the structure of the table in question, while the second one is tasked with importing the records of the source lookup database, which was previously downloaded as a CSV file from Webnet77's web site.
Now that you remember how the previous source files do their things, it's time to build a pair of simple PHP applications. These applications will take advantage of the functionality of the "iptocountry" MySQL table created in the previous tutorial to map the IP addresses of different users to their originating countries.
To learn how these sample PHP programs will be developed, please click on the link that appears below and keep reading.
blog comments powered by Disqus