donglu8334 2019-06-20 10:03
浏览 73

检测用户代理然后将其设置为cookie有时会导致重定向循环

I have the following scenario:

  • I have two websites, one for mobile (m.mydomain.com) and one for desktop (mydomain.com)

  • I decide which site to load using user agent detection

  • Once this detection happened, I keep the user's device information in a cookie called: device.
  • This cookie can contain one of the following values: desktop or mobile.
  • If the user comes to the site with a device cookie, I skip the user agent detection and I assume that the user is really using the device what is written in the cookie.

enter image description here

(Note to the image: It works the opposite direction as well, when the user wants to open a mobile link from desktop. When the mobile site sets the cookie, the cookie domain will be m.mydomain.com)

The error: So most of the times this mechanism is in sync but still sometimes I experience redirect loops, and I don't really understand the reason of that. Basically one domain thinks that it is desktop, the another thinks it is mobile and they play an infinite loop with the redirection. After 3 redirects the browser crashes with too many redirects error.

It is also important to mention that I never experienced this on a real mobile device, only when I was switching in the chrome inspector between mobile and desktop user agents.

My ideas were that:

  • Perhaps the cookie setting failed before the redirect
  • Perhaps the domain naming causes confusion somehow when I want to access the value.
  • Perhaps reading the cookie value fails
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3