+ Reply to Thread
Results 1 to 3 of 3

Thread: Geo target your visitors

  1. #1
    Programming God AfTriX is on a distinguished road
    Join Date
    Jan 2007
    Location
    Chicago
    Posts
    586

    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 11:24 PM. Reason: Please use the [php], [code], and [html] functions when appropriate, makes it easier to read. :)

  2. #2
    Programming God xtraze is an unknown quantity at this point
    Join Date
    Dec 2006
    Location
    Sri lanka
    Posts
    908
    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.

  3. #3
    Programming God AfTriX is on a distinguished road
    Join Date
    Jan 2007
    Location
    Chicago
    Posts
    586
    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. how to get ip of the visitors
    By kool in forum General Programming
    Replies: 1
    Last Post: 08-22-2007, 08:42 AM
  2. how to get ip of the visitors
    By AntonyLT in forum ASP, ASP.NET and Coldfusion
    Replies: 1
    Last Post: 06-14-2007, 05:43 AM
  3. 14 Ways to SEO Wordpress
    By xtraze in forum Search Engine Optimization
    Replies: 4
    Last Post: 04-23-2007, 05:03 PM
  4. Target Words
    By mysticalone in forum Affiliate Marketplace
    Replies: 0
    Last Post: 01-25-2007, 02:15 AM
  5. Getting your Visitor's Details Using PHP
    By Ronin in forum PHP Forum
    Replies: 1
    Last Post: 05-15-2006, 01:56 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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