-1

In the document root I have the files:

en.php
es.php
pt.php
...

How can I load the PHP file according to the language of the visitor without affecting the query URL? And that the URL is kept mysite.com/url-required

palaѕн
  • 72,112
  • 17
  • 116
  • 136

1 Answers1

0

The PHP can't really tell the language of the guest. It can use the IP address of the visitors from the requests and load the language files accordingly, but keep in mind that a lot of people are moving to different countries or travel temporary to different countries, thus they might wont be able to understand anything from the website. The same happens if someone is using tor browser or masking their IP address.

A bit more accurate method is to use js to determine the web browser's language or the system language, however these are also more like guess works, because it's also possible that someone has to use a PC on different language.

So the best if you provide a way for the user to be able to switch the language, and then store this information in a cookie on their PC, so it wont switch back as they look around on the website.

Random Dude
  • 872
  • 1
  • 9
  • 24