You code returns an error: PHP Parse error: syntax error, unexpected 'default' (T_DEFAULT) in yourfile.php on line
. It means that you're misusing default
in switch
statement. Replace your last part of your code with this:
default:
if(visitor_country() == "Germany") {
$lang_file = 'lang.de.php';
echo "Germany";
} else {
$lang_file = 'lang.en.php';
echo "Not in Germany";
}
Take out default
from inside of if/else
statement.
EDIT 1:
Make sure that PHP displays ERRORS
, WARNING
and NOTICES
to properly debug your code:
ini_set('display_errors', -1);
EDIT 2:
If it was working without the switch
statement, like you said, then you must make sure that files lang.en.php
/lang.de.php
really exist.
EDIT 3:
You are suppressing errors with having @
in-front of json_decode(file_get_contents
. Most likely you would have to edit your php.ini
and enable allow_url_fopen
to make it work. I bet if you remove @
, you will get an error:
Warning: file_get_contents(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in
I wouldn't strongly recommend using this kind of method to detect user language and enabling allow_url_fopen
as it's possible security flaw! In case you're interested, I will provide you with much better solution for determining user browsers' language.