更改用户代理后,PHP会话被破坏 [英] PHP session is destroyed after user agent change

查看:80
本文介绍了更改用户代理后,PHP会话被破坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的地址example.com/page1.例如,访问者的用户代理是这样的:Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_2 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B146.我运行session_id(),PHP会话ID为12345.我可以在临时文件夹中看到"sess_12345"文件.它具有所有会话变量.

I have such address example.com/page1. For example visitor's user agent is like this: Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_2 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B146. I run session_id() and PHP Session ID is 12345. I can see "sess_12345" file inside temporary folder. It has all session variables in it.

经过一些处理后,我将他/她重定向到example.com/page2.访客的用户代理更改为:Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_2 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B146 Twitter for iPhone.我再次运行session_id(),发现ID仍然是12345.但是当我检查"sess_12345"文件时,我看到它已被删除.

After some processing I redirect him/her to example.com/page2. Visitor's user agent changes to this: Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_2 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B146 Twitter for iPhone. I run session_id() again and find out that ID is still 12345. But when I check "sess_12345" file, I see that it is deleted.

仅当用户从"Twitter for iPhone"应用程序进入我的网站时,才会发生这种情况.我猜会话文件由于用户代理更改而被删除,但是我不确定.可能是什么原因?

This happens only when users come to my website from "Twitter for iPhone" application. I guess session file is deleted because of user-agent change, but I'm not sure. What can be the cause?

(除了这种情况外,会话均能成功运行.我使用CakePHP 2.4)

(Sessions work successfully except this case. I use CakePHP 2.4)

推荐答案

Cake的设置将检查浏览器的用户代理.如果更改,将破坏会话.关闭此设置:

Cake has a setting which will check the user agent of the browser. If it changes will destroy the session. Turn this setting off:

Session.checkAgent

这篇关于更改用户代理后,PHP会话被破坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆