Displaying a code only if user is from a certain country or speaks a certain language

Discussion in 'Programming' started by BannanoPeel, Mar 19, 2011.

  1. #1
    I want to have some sort of variable on my website so that if a visitor comes from a different country then I can display something special on my website.

    However I'm unsure how to do this, or even if it's possible. If not I'm pretty sure that you can do some sort of variable with languages (i.e what language is default on their browser). If someone could help me with that I would really appreciate it.

    Basically what I'm looking for is:

    {if $English }
    nothing
    {else/$foreign language}
    something

    or

    {if $USA}
    nothing
    {if $other country}
    something
     
    BannanoPeel, Mar 19, 2011 IP
  2. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can get the browser's default language but of cause not everyone in a country will automatically have their PC set to the native language - I live in the UK but our laptop is set to Spanish

    A country generally has to be worked out by their IP, but again there can be circumstances (especially with people using corporate systems) where you may get a false result. As I VPC into our network anywhere in the world I am my IP will show me being in the UK.

    We do something similar with http://www.virtualassistantdirect.com/ which detects your browsers language and then sends you either to the spanish or english version of the site.
     
    AstarothSolutions, Mar 19, 2011 IP
  3. jareso

    jareso Well-Known Member

    Messages:
    70
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #3
    I did one simple script for you. It is not 100% accurate, but it can be a way to go ...

    
      $lng = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
      if ($lng == '')
        echo 'Unknown country!';
      else if (strlen(stristr($lng,'sk')) > 0)
        echo 'Slovakia!';
      else if (strlen(stristr($lng,'en-us')) > 0) 
        echo 'USA!';
      else
        echo 'Some other country ...';
    
    Code (markup):
    Enjoy! :D
     
    Last edited: Mar 19, 2011
    jareso, Mar 19, 2011 IP
  4. rod.maqstuirt

    rod.maqstuirt Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Just Use API:
    http://ipinfodb.com/ip_location_api.php
    Code (markup):
     
    rod.maqstuirt, Mar 21, 2011 IP