Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Ads on site by country

Posted on 2008-06-24
7
Medium Priority
?
209 Views
Last Modified: 2013-11-19
I'm wanting to display some ads on my website, but like this:

If Visitor from England then
     show custom England ads
else
    show regular ads to the rest of the world.


Is there anyway I can do that?
0
Comment
Question by:PeterErhard
7 Comments
 
LVL 2

Expert Comment

by:ayus80
ID: 21854048
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 21854445
0
 
LVL 4

Accepted Solution

by:
snrudda earned 2000 total points
ID: 21855360
First, check client IP via some IP-to-Country database (say, see http://www.maxmind.com/app/geoip_country for). If you have huge lookup amount this may be good solution, but the DB is big and you need to store and update it from time to time.

But I'd rather use country RBL such as zz.countries.nerd.dk to get your info fast and accurate enough. Example code below:

P.S. If you care just for one country, alternatively you can use per-country RLBs, say jp.countries.nerd.dk, to get all IPs that belongs to Japan (note country code as first part of RBL name). See http://countries.nerd.dk/more.html on that.
<?
 
$rbl = "zz.countries.nerd.dk";
$remote = $_SERVER['REMOTE_ADDR'];
if (preg_match("/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/", $remote, $matches)) {
  $rblhost = $matches[4] . "." . $matches[3] . "." . $matches[2] . "." . $matches[1] . "." . $rbl;
  $resolved = dns_get_record ($rblhost, DNS_TXT);
  $country = (isset($resolved[0]['txt'])) ? $resolved[0]['txt'] : 'N/A';
}
 
echo $country;
 
?>

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 44

Expert Comment

by:scrathcyboy
ID: 21859475
First, this is not easy to do.  If you want to catch everyone correctly, you have to use something like the above suggestions.  If you only want to select a few countries, like .uk, .ca, .com, .au, .nz and so forth, you can use in PHP --  HTTP_Referrer - and then use a lookup of general IP classes per country --

http://www.google.com/search?num=30&q=IP+addresses+by+country  (many ways, so a general link)

And then have a lot of CASE statements in the PHP file to select which ads are relevant.  It is a lot of coding.  Otherwise, you could provide a world map and have them click on a location, which I think makes the website much more interesting.  Then you only need to use javascript and the MAPAREA function do decide what ads to feed them.

Curious -- what websites are running on Lord Howe?  When I was there eons ago it was just a very sleepy little hidden island with nothing going on ....
0
 
LVL 4

Expert Comment

by:snrudda
ID: 21864371
scrathcyboy, not HTTP_Referrer but REMOTE_ADDR! Strange to see that from someone who titled as Master. And world map to click on is pretty strange too when it comes to ads geo-targeting.

The question is easy indeed, the only thing to consider is if PeterErhard would host geo database by himself or prefer to use external DB (such as geo RBL), keeping in mind that external service may be down without notice. I'd say the second options is much easier to deal with (nether to care about DB updates nor keep that rather large DB on own server) and ads can be shown even if RBL temporary refuse to answer.
0
 

Author Comment

by:PeterErhard
ID: 21864589
Thanks a lot for all the responses guys, much appreciated.

Will give them a try :)
0
 
LVL 4

Expert Comment

by:snrudda
ID: 21864640
You're always welcome Peter, good luck!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question