Redirect location comes from browser cache. Cookie modification not applied
I use KO3.1 & php 5.3.3
In my controller 'action_lang' with route 'lang/code'开发者_如何学C I set user UI language and save it into the cookie with:
Cookie::set('language', $code)
Right after this I call:
Request::current()->redirect('/')
to move to the main page, where I have
echo Cookie::get('language')
to print current language.
The problem is my browser reads redirected page from it's CACHE thus Cookie::get('language') always shows the SAME value. The only way is to force the browser to refresh with F5, then it change as expected but that's not the way it should work. / It should change instantly!
Is there something wrong with this method? or its just me too tired... I'm sure this worked fine some time ago, with the very same browser and KO2.
please help
The beahvior of the browser might actually correct, if the cache headers indicate it. The correct solution would be to forbid caching of the URI contents. However, some browsers have issues here and it might not be desired to not allow the browser caching the URL at all.
A simple solution to fool the browsers for reloading the page in your exact case is to append a random parameter to the URL like ?refresh=$time
with $time
being the current time stamp.
精彩评论