CodeIgniter 会话类在 Chrome 中不起作用 [英] CodeIgniter session class not working in Chrome
问题描述
我在 codeigniter 项目中创建了一个登录系统,它在 Firefox 中运行良好但在 Chrome 中不起作用,数据获取和设置为会话但是当此代码将控制重定向到管理/仪表板时,我们再次检查会话数据.如果会话数据不存在,那么代码将重定向用户再次登录……我的代码在下面,我不知道 codeigniter 中的这个会话/cookies 有什么问题.?
I have created a login system in codeigniter project, which is working fine in Firefox but doesn't work in Chrome, data fetch and set for session but when this code redirect control to admin/dashboard, there we check session data again. If session data not exist then the code will redirect user to login again............ My code is below, and i don't know what is wrong with this session/cookies in codeigniter.?
$data = array(
'user_id' => $user->id,
'name' => $user->name,
'user_type' => $user->type,
'username' => $user->username,
'is_logged_in' => true
);
$this->session->set_userdata($data);
//echo "user ".$this->session->userdata("username"); exit;
redirect("admin/dashboard", "location");
我已经搜索了很多,但没有人在这种情况下工作,例如在配置文件中更改cookie_domain",但什么也没发生....
I have search alot for but no one work in this situation, like a change "cookie_domain" in config file but nothing happened....
推荐答案
我也遇到过这种情况,并通过将会话到期时间增加到一天来修复它.
I have also faced this situation and fixed it by increasing session expiry to one day.
更新
出现此问题是由于用户的时区和网络服务器位置之间的差异,例如我住在巴基斯坦,比美国时区早 10 小时,我的服务器在美国.我在巴基斯坦时间 17/10/2012 14:00 请求页面.美国的时间是 17/10/2012 4:00,因为网络服务器在美国并且会话过期时间设置为 2 小时,服务器发送的 cookie 设置为在 17/10/2012 6:00 过期.现在浏览器与您的本地电脑时间交互,它获得时间 17/10/2012 14:00 因此它删除 cookie 或您的 cookie 总是根据您的请求刷新.因此最好将会话到期时间设置为 1 天,因为新西兰和美国之间的最大时区差异是 17 小时(我不确定差异可能是我错了).所以你的 cookie 至少会存活 7 小时
This problem occurs due to difference between timezones of user and webserver location e.g. I live in Pakistan which is 10 hours ahead of US timezone and my server is in US. I request the page at 17/10/2012 14:00 at Pakistan time. The time in US is 17/10/2012 4:00 since webserver is in US and session expiry is set to 2 hours the cookie sent by server is set to expire at 17/10/2012 6:00. Now browser interacts with your local pc time and it gets time 17/10/2012 14:00 therefore it deletes the cookie or your cookie always refreshed on your request. Therefore its best to set session expiry to 1 day because the largest timezone difference is 17 hours between new zealand and US (i am not sure about difference may be i am wrong). So your cookie will at least keep alive for 7 hours
这篇关于CodeIgniter 会话类在 Chrome 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!