CodeIgniter会话类在Chrome中不起作用 [英] CodeIgniter session class not working in Chrome

查看:110
本文介绍了CodeIgniter会话类在Chrome中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在codeigniter项目中创建了一个登录系统,它在Firefox中工作正常,但不工作在Chrome,数据提取和会话设置,但当这个代码重定向控制到管理/仪表板,我们再次检查会话数据。如果会话数据不存在,那么代码将重定向用户再次登录............我的代码在下面,我不知道这是什么错误的会话/ cookie在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);
// echouser。$ this-> session-> userdata(username);出口;
redirect(admin / dashboard,location);

我已经搜索,但没有人在这种情况下工作,如更改 cookie_domain 在配置文件,但没有发生....

解决方案

我也面临这种情况,将会话到期时间增加到一天。



UPDATE



它通过延长会话到期来工作?





此问题的发生是由于用户和web服务器位置的时区之间的差异,例如我住在巴基斯坦比美国时区提前10小时,我的服务器在美国。我请求页面在17/10/2012 14:00在巴基斯坦时间。在美国的时间是17/10/2012 4:00,因为web服务器在美国和会话过期设置为2小时由服务器发送的cookie设置为到期在17/10/2012 6:00。现在浏览器与您的本地pc时间互动,它获取时间17/10/2012 14:00因此它删除cookie或您的cookie总是刷新您的请求。因此,它最好设置会话到期1天,因为最大的时区差异是新西兰和美国之间17小时(我不知道差异可能是我错了)。因此,您的Cookie至少会保持活动7小时


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"); 

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.

UPDATE

Why it works by extending session expiry?


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屋!

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