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
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.
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!