The MU forums have moved to WordPress.org

How to run code on visitors from country x only (8 posts)

  1. Klark0
    Member
    Posted 13 years ago #

    I have some html that I need to show to visitors from lets say the US and Canada only.

    Any ideas on how I can do that with MU.

  2. andrea_r
    Moderator
    Posted 13 years ago #

    Run some stuff that checks for IP range. I know it can be done pretty easily with php.

    Either stick it in the template where you want it to show, or hook into the footer.

  3. tdjcbe
    Member
    Posted 13 years ago #

    We had a discussion along this topic a few days ago:

    http://mu.wordpress.org/forums/topic.php?id=5508

  4. Klark0
    Member
    Posted 13 years ago #

    mmmm.. I'll need a solution that's javascript so that WP-SuperCache doesn't come into play.

    Any ideas ? Examples ?

  5. tdjcbe
    Member
    Posted 13 years ago #

    Are we talking about code that runs before anything is displayed or somewhere during the page serving?

    If before, I'd look at htaccess but a quick google doesn't find anything that I can point you to.

    If during viewing, only thing right off I'm finding is this:

    http://www.geobytes.com/GeoDirection.htm

    I'm sure it can be done as it's used all the time in advertising. Only examples I'm finding though is using ip address lookups to block access via htaccess though.

  6. andrea_r
    Moderator
    Posted 13 years ago #

    I'm not sure without checking, but I know at perezhilton.com (shaddap - I'm not a regular I swear) he was displaying a different background for Canadian visitors.

    It was easy enough to uncover by viewing the source of the page.

  7. Klark0
    Member
    Posted 13 years ago #

    http://www.niharsworld.com/2008/06/25/how-to-show-chitika-premium-to-us-visitors-and-eminimalls-to-non-us-visitors/

    This seems like what I'm looking for...But i'm have trouble with the code.

    The code I want to show differently to US/Canada visitors (vs the rest of the world) is javascript ..and you can't display javascript within javascript ..or can you ? It does not parse when I try.

    <script language="JavaScript">
    
    var country_code = geoip_country_code();
    
    if (country_code == "US" || country_code == "CA"){ 
    
    //SCRIPT FOR US/CANADA
    
    }else{
    
    //REST OF THE WORLD
    
    }
    
    </script>
  8. Klark0
    Member
    Posted 13 years ago #

    Alright my solution was
    http://www.openx.org/

    :)

About this Topic