+ Reply to Thread
Results 1 to 3 of 3

Thread: Geo target your visitors

  1. #1
    AfTriX is offline Programming God
    Join Date
    Jan 2007
    Location
    Chicago
    Posts
    586
    Rep Power
    0

    Geo target your visitors

    Have you ever wanted to find out where a visitor lives?

    I had the need a week ago when an ad company said that they had lots of advertisers that needed UK visitors. So they asked if I could show their ads for all my UK visitors. Now I have a solutions that I thought that I would share with you.

    First of all download and unpack Maxminds geoip database. It's free (atleast this version) and can find out what country a visitor come from depending on their IP address. They say it's 97% accurate.

    Download the database and unzip (gunzip -d GeoIP.dat.gz on linux)

    Download the PHP api and save as geoip.inc

    This database is pretty big, so we only want to use it as few times as possible. Because of that we will store a visitors countryCode in a cookie. So it's only the first time he/she visits our site we use the databse. The reset of the time the cookie i used. Smart :-)

    Code:
    function getCountryCode()
    {
    if(isset(
    $_COOKIE["geoCode"]))
    {
    $countryCode $_COOKIE["geoCode"];
    }
    else
    {
    include(
    "geoip.inc");
    $gi geoip_open("GeoIP.dat",GEOIP_STANDARD);
    $countryCode geoip_country_code_by_addr($gi$_SERVER["REMOTE_ADDR"]);
    geoip_close($gi);
    setcookie("geoCode"$countryCodetime()+15552000"/"".999tutorials.com"0); //6 months cookie
    }

    return 
    $countryCode;

    Call this function and you will get US if the visitor is from USA and SE if the visitor is from Sweden.

    So if you want to show special ads for all swedes you can use this code:

    Code:
    if(getCountryCode() == "SE")
    {
    echo 
    "hello sweden";
    include(
    "ads/adsForSwedes.inc");
    }
    else
    {
    include(
    "ads/adsForTheRestOfTheWorld.inc");

    If you want show the visitors flag or send the visitor to a specific page... Use this function to find out the country. Just use your fantasy :-)

    The database is updated once every month, in the beginning so make sure you update...

    Good luck!!

    Source: Front Page | Pixel Groovy
    -
    Last edited by John; 01-06-2007 at 09:24 PM. Reason: Please use the [php], [code], and [html] functions when appropriate, makes it easier to read. :)

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    xtraze is offline Programming God
    Join Date
    Dec 2006
    Location
    Sri lanka
    Posts
    911
    Rep Power
    0
    Excellent script dude, I really like it.
    Especially as my new site is for only Sri lanka and I can inform this to others by this command, but is Srilanka included in the Database ? as it's BIG, it may take time first time.
    And nowadays people block Cookies lol, I saw on a thread saying so, I clear cookies once a day or less.

  4. #3
    AfTriX is offline Programming God
    Join Date
    Jan 2007
    Location
    Chicago
    Posts
    586
    Rep Power
    0
    Thanx a bunch!!

    And you don't want to worry about cookie things, if you are going to publish targeting the users only in Sri Lanka. Because most of the users (almost more than 90%) in Sri Lanka don't block the cookies as for the Stats.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. No rule to make target... Please help
    By FritoBandito in forum C and C++
    Replies: 2
    Last Post: 05-16-2008, 11:04 AM
  2. Slow rotation towards target
    By Maurice_Z in forum Programming Theory
    Replies: 5
    Last Post: 01-02-2008, 09:00 AM
  3. how to get ip of the visitors
    By kool in forum General Programming
    Replies: 1
    Last Post: 08-22-2007, 06:42 AM
  4. how to get ip of the visitors
    By AntonyLT in forum ASP, ASP.NET and Coldfusion
    Replies: 1
    Last Post: 06-14-2007, 03:43 AM
  5. Target Words
    By mysticalone in forum Affiliate Marketplace
    Replies: 0
    Last Post: 01-25-2007, 12:15 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts