19, September 2014

Webdigity tutorials : Php geotargeting techniques

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Tutorials @ webDigity
Php geotargeting techniques

Subscribe to our tutorials feed!

There are many cases that we need to display different content to our users depending on the location that they are visiting our site. In this tutorial we will give some examples regarding geo targeting with php.

First of all I would like to say how geotargeting is important for the monetization of a web site. For instance you can use adsense and replace one good spot with an affiliate advertisement only for US visitors (as US are buying more frequently). Additionally there are many ad networks (eg. Yahoo publisher network) that require to display their ads only to US visitors, or others that pay more for US visitors.

There are many ways to implement this in your web site, though the most simple I found is by using Maxmind's geolocation database(there is a free version in their site)

After you download the database, you need to get the pure php module which is an API for the database (the database is a text file)

Put those two in a directory, and now you are done. Here is how you can use it to identify if someone is coming from United States :

Code:
<?php
require_once 'geoip.inc.php';
$gi geoip_open'GeoIP.dat'GEOIP_STANDARD );
if ( 
geoip_country_code_by_addr($gi$_SERVER['REMOTE_ADDR']) == 'US' )
echo 'Hello US guy';
geoip_close($gi);
?>

Do you like this tutorial?
Feel free to share it with others using Dzone or your favorite bookmarking service. You can see related discussions in our php forum
This tutorial posted by Nikolas from Sublime Directory

Sponsors :

Code library menu :
[ Tutorials home | Submit a tutorial ]

User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Sep 19, 2014, 09:45:17 am





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2014 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.