Solved

Ads on site by country

Posted on 2008-06-24
7
202 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

860 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