Auto detect language and redirect user

后端 未结 5 1447
孤街浪徒
孤街浪徒 2020-12-13 21:05

I am doing my own website and I managed to write some code that makes directs user to the language version according to the browser\'s language. Here is the script:

5条回答
  •  时光说笑
    2020-12-13 21:59

    Well, I came across some problems with my code which is no surprise due to I am not a PHP expert. I kept therefore on searching for a possible solution and I found the following code on another website:

    
    

    This did the job perfectly! I only had a problem left. There was no way to change language, even with direct links into another language because as soon as the page was loading, the php block would redirect me to the borwser's language. This can be a problem if you are living in another country and have for instance Swedish as a mother language but you have your browser in English because you bought your computer in the UK.

    So my solution for this issue was to create folders with a duplicate version for every language (even the one for the main language) without this php code on the index.html (and therefore not index.php). So now my website is auto detecting the language and the user also has the option to change it manually in case of they want!

    Hope it will help out someone else with the same problem!

提交回复
热议问题