Reputation: 156
I am making a website in 2 languages. Is it possible to check it in which country the user is, so that I can switch the language automatically for the user? I also have a switch option in my menu with a _GET. I have this piece of code in the beginning:
if (isset($_GET['taal'])) {
$taal = $_GET['taal'];
} else {
$taal = 'ENG';
}
switch ($taal) {
case 'NL':
include('NL.php');
break;
case 'ENG':
include('ENG.php');
break;
default:
include('ENG.php');
break;
}
Upvotes: 0
Views: 155
Reputation: 3665
First you need to get the user country by ip address:
$country = ip_info($_SERVER['REMOTE_ADDR'], 'Country');
if($country=='Netherlands'){
$taal = 'NL';
}else{
$taal = 'ENG';
}
switch ($taal) {
case 'NL':
include('NL.php');
break;
case 'ENG':
include('ENG.php');
break;
default:
include('ENG.php');
break;
}
Upvotes: 1
Reputation: 2682
I would like to point you to a similar question with a relevant answer.
As you can tell from this answer the first step to identifying a user's location/country would be to read their IP address. This can sometimes be a little tricky due to proxies. A good way to identify a user's IP using PHP can be found here.
Also, if you're looking to create a multi-language platform you may want to first read, understand and adhere to basic industry standards. If you wanted to, you could use PHP for this like you're already doing; or you can use universal language files which would have the benefit of being cross-platform (PHP,Java,C# etc.).
Upvotes: 1