开发者

CodeIgniter Cookies Working In FF, But Not Chrome Or IE

I've built a site in CI, and have a login system, which works fine开发者_如何学运维 in Firefox but not Chrome or IE. In those two if the username and password are correct it just redirects (i think) back to the login page, not to the login error page, or to the site home (as it should). I've noticed that it doesn't seem to be setting a cookie in Chrome, but it does in FF.

Here's the code in my controller which sets the cookie and redirects after authentication:

            $newdata = array(
                   'username'  => $_POST['login_username'],
                   'real_name' => $name,
                   'user_id' => $uid,
                   'logged_in' => TRUE
               );

            $this->session->set_userdata($newdata);
            //echo $newdata;
                redirect('/site/index');    

Any ideas why this might be happening?

Thanks


I experienced this problem too ... session userdata lost for Chrome and IE, but ok on Firefox. It was due to an incorrect setting in config/config.php

I had to explicitly set cookie_domain To make it automagic in the future I used this command ... ripped off the CI forums.

$config['cookie_domain'] = str_replace("http:/","",str_replace("https://","", $config['base_url']));

I added this line and all was ok.


Check that $_SESSION really is set. On CI you may need to exit gracefully to flush out whats in $this-sessionto the 'real' session variable.

add a echo serialize($_SESSION) so you know whats going on (before the redir).

and check how to end a Ci-request gracefully.


Adjusting the cookie name can fix the issue in the CI configs to remove underscores works wonders. The article CodeIgniter Session Problem in IE explains the details quite well.


For me it solved just adding more time to the cookie, I had 3600 so I changed to 7200. Seems to be a problem with time on my production site. May help someone.


In my case, the problem was that $config['base_url'] was empty. So i set it to my domain

$config['base_url'] = 'http://yourdomain.com/';


CodeIgniter has some problem if the specified domain for cookies is localhost, I've set a fake domain with a real domain's name structure into the hosts file and it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜