Solved

Ads on site by country

Posted on 2008-06-24
7
199 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 500 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now