Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

arpero's avatar

Language switch not working when installed on shared hosting

Hi everyone,

I have made a website in Laravel, a multilingual website, so far English and French. To change the language there is method thats ets the value in the sessions and it's called in the Route Route::get('home/lang/{any}','HomeController@getLang');

HomeController

public function getLang( Request $request , $lang) { $request->session()->put('lang', $lang); return Redirect::back(); } In the index fucntion of the same controller it is:

public function index( Request $request) { \App::setLocale(\Session::get('lang')); }

With this code Laravel is able to translate the strings. It works like a charm in my local PC, but when I install in a shared server (in my case, Hostgator), it doesn't work. When I click on the webpage to switch to another language, it's just refreshing the page and the same original language shows. Why does this happen? What do I have to do for this to work in a shared hosting? Is that a kind of protection Laravel has?

I will appreciate any help.

Best wishes, Ariel

0 likes
5 replies
Mahin's avatar

can you provide the link to your hosted app?

arpero's avatar

In fact, when I'm in French and I switch, in the session file at /storage/frameworks/sessions I see the session variable changes a:4:{s:6:"_token"; ... "lang";s:2:"EN";s:9.... :{}}} but the page doesn't update to English It's like if it can't read the value and it keeps the lang=FR applied before

arpero's avatar

Hello Mahin, Do you have an idea of why this is happening? Thanks in advance.

arpero's avatar

For more details, session seems to be working OK, I print before executing the Lang::get in the views \Log::info("Get Locale in Home page: ".\App::getLocale()); and it prints correctly to the language that I have just switched to, b but then the {!! Lang::get('xxx') !!} doesn't work, nor the {{ trans('xxx') }} Languages files are well placed and everything works locally, but not in the shared hosting server.

Any help will be welcomed, Ariel

Please or to participate in this conversation.