Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

CodeIgniter session class not working in Chrome

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....

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...