重定向位置来自浏览器缓存。未应用 Cookie 修改
我用的是KO3.1& php 5.3.3
在我的控制器“action_lang”和路由“lang/code”中,我设置用户 UI 语言并将其保存到 cookie 中:
Cookie::set('language', $code)
在此之后我调用:
Request::current()->redirect('/')
移动到主页,我必须在其中
echo Cookie::get('language')
打印当前语言。
问题是我的浏览器从缓存中读取重定向页面,因此 Cookie::get('language') 始终显示相同的值。唯一的方法是强制浏览器使用 F5 刷新,然后它会按预期更改,但这不是它应该工作的方式。 / 它应该立即改变!
这个方法有什么问题吗?或者只是我太累了... 我确信不久前使用相同的浏览器和 KO2 效果很好。
请帮忙
I use KO3.1 & php 5.3.3
In my controller 'action_lang' with route 'lang/code' 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果缓存标头指示的话,浏览器的行为实际上可能是正确的。正确的解决方案是禁止缓存 URI 内容。但是,某些浏览器在此处存在问题,并且可能不希望根本不允许浏览器缓存 URL。
欺骗浏览器在您的具体情况下重新加载页面的一个简单解决方案是在 URL 中附加一个随机参数,例如
?refresh=$time
,其中$time
为当前时间时间戳。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.