Ajax software
Free javascripts
↑
Main Page
$country_code = mysql_escape_string($country_code);
$country_name = mysql_escape_string($country_name);
// build and execute the INSERT query
$q = “INSERT INTO geo_target_data (start_ip_text, end_ip_text “ .
“, start_ip_numeric, end_ip_numeric, country_code, country_name)“ .
“VALUES (‘$start_ip_text’, ‘$end_ip_text’, ‘$start_ip_numeric’, “ .
“‘$end_ip_numeric’, ‘$country_code’, ‘$country_name’)“;
mysql_query($q);
}
}
?>
5.
Create a file named
geo_targeting_prepare.php
in your
seophp
folder, and type this code:
<?php
// load the geo-targeting library
require_once ‘include/simple_geo_target.inc.php’;
// update the geo-targeting database
SimpleGeoTarget::importGeoTargetingData();
echo “Geo-targeting database updated!”
?>
6.
Load
http://seophp.example.com/geo_targeting_prepare.php
. It will take a while until
the geo-targeting database is copied into your database, so be patient. At the moment of writing,
there are approximately 60,000 records in the database. Once the process is finished, you should
get a message saying “Geo-targeting database updated!”
Note that the sample script simply deletes the old data and refreshes it with new data whenever it is run.
To test that the
geo_target_data
table was populated correctly, you can open it for browsing
using phpMyAdmin, as shown in Figure 11-7.
7.
Test the geo-targeting library now with a real example! Create a file named
get_targeting_
test.php
in your
seophp
folder, and type this code in:
<?php
// load the SimpleGeoTarget library
require_once ‘include/simple_geo_target.inc.php’;
// display geo-targeted welcome message
if (SimpleGeoTarget::isRegion(“RO”))
{
echo “Welcome, visitor from Romania!”;
}
else if (SimpleGeoTarget::isRegion(“US”))
{
echo “Welcome, visitor from United States!”;
}
else if (!SimpleGeoTarget::getRegion())
239
Chapter 11: Cloaking, Geo-Targeting, and IP Delivery
c11.qxd:c11 11:01 239
Ajax software
Free javascripts
→