JavaScript Editor Ajax software     Free javascripts 



Main Page

/* methods used for importing the geo-targeting database */
// imports MaxMind’s geo-targeting database into the geo_target_data table
function importGeoTargetingData()
{
// open the geo-targeting file
$csv_file_handle = fopen(GEO_TARGETING_CSV, ‘r’);
// continue only if the geo db file was opened successfully
if (!$csv_file_handle)
{
echo “Could not open the geodb file.”;
return;
}
// Connect to MySQL server
$dbLink = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
or die(“Could not connect: “ . mysql_error());
// Connect to the seophp database
mysql_select_db(DB_DATABASE) or die(“Could not select database”);
// lock the simple_geo_target file for writing
mysql_query(‘LOCK TABLES simple_geo_target WRITE’);
// remove all existing entries from the table
$q = “DELETE FROM geo_target_data”;
mysql_query($q);
// parse each record from the geo-targeting file and save it to the database
while (($data = fgetcsv($csv_file_handle, 10000, “,”)) !== false)
{
SimpleGeoTarget::_insert($data[0], $data[1], $data[2],
$data[3], $data[4], $data[5]);
}
// unlock the tables
mysql_query(‘UNLOCK TABLES’);
// close database connection
mysql_close($dbLink);
// close the file handler
fclose($csv_file_handle);
}
function _insert($start_ip_text, $end_ip_text, $start_ip_numeric,
$end_ip_numeric, $country_code, $country_name)
{
// escape input data
$start_ip_text = mysql_escape_string($start_ip_text);
$end_ip_text = mysql_escape_string($end_ip_text);
$start_ip_numeric = mysql_escape_string($start_ip_numeric);
$end_ip_numeric = mysql_escape_string($end_ip_numeric);
238
Chapter 11: Cloaking, Geo-Targeting, and IP Delivery
c11.qxd:c11 11:01 238


JavaScript Editor Ajax software     Free javascripts