views:

2630

answers:

4

I'm still new to code igniter and I'm having problems getting the login system to work.

The login always works when I use Firefox. The login consistently works on some IE7 browsers but consistently fails on other IE7 browsers.

When tracing the code, I see that the models/redux_auth_model.php does successfully authenticate the user, it writes user information into the $this->session->set_userdata() and it redirect them to a member's page of my choosing. Here's the code:

public function login($identity = false, $password = false)
{
            $identity_column = $this->config->item('identity');
            $users_table     = $this->tables['users'];

            if ($identity === false || $password === false || $this->identity_check($identity) == false)
            {
                return false;
            }

            $query = $this->db->select($identity_column.', email, password, group_id')
                           ->where($identity_column, $identity)
                           ->where('active', 'Active')
                           ->limit(1)
                           ->get($users_table);

        $result = $query->row();

        if ($query->num_rows() == 1)
        {
            //$password = $this->hash_password_db($identity, $password);

           if (!empty($result->activation_code)) { return false; }

                if ($result->password === $password)
                {
                    $this->session->set_userdata($identity_column,  $result->{$identity_column});
                    $this->session->set_userdata('email',  $result->email);
                    $this->session->set_userdata('group',  $result->group_id);
                    return true;
                }
        }

        return false;
}

I did a variable dump of $this->session in both IE7 and FF and confirmed that all the userdata is intact before the redirect. The session had my email information, group information and $identity_column information.

However, after the redirect, the session data is empty on some IE7 browsers, which is why CI keeps booting me out of the system. It's fully intact on other IE7 browsers and always intact in Firefox.

Why would session data be browser dependent?

Any ideas on how to troubleshoot this further? I am baffled...

A: 

This is an issue that someone made a 3rd party fix for, it patches the session controller. Let me dig it up. I have used it in my codeigniter setups since it was first noted.

This issue is IE7/IE8 specific with redirects or frames.

EDIT

Here is the reference that I have found before, it helped me with the IE issue. Hopefully this is what is causing you headaches: http://www.philsbury.co.uk/blog/code-igniter-sessions

Jakub
This bug is so frustrating. I really hope it's the same problem you're mentioning...crossing my figers
John
I have updated my answer with reference info to the fix that did it for me. Good luck.
Jakub
hmm...the link gives me a 500 Internal Server Error....
John
It was working at time of post, check back later, it should be back. The link works... their server doesn't.. right now.
Jakub
Ok, thanks. The page finally loaded, but the download link is broken. So I did a search for a similar file name and found http://codeigniter.com/wiki/File:Session.php.zip/ Hopefully that's the same file. I unzipped, put Session.php into the application/libraries folder, added a "Session" to $autoload['libraries']. The problem still isn't fixed. Did I miss a step?
John
+2  A: 

It is a frustrating problem with the Codeigniter database session class, in the end I resorted to using native sessions using the drop-in replacement found here: http://codeigniter.com/wiki/Native%5Fsession/

pǝlɐɥʞ
Thanks, I will try this solution as wel. I couldn't figure out how to enable Native Session though. Is there another reference I can read? Thanks
John
you just drop the session.php file in application/libraries No code change required in your application
pǝlɐɥʞ
YES! IT worked! Thank you!
John
A: 

This doesn't work with the latest version of CI. 1.7.2 ... what a waste of time this is

JT
A: 

The session class works fine in several of my projects including IE6/7/8 support (including multiple releases of CI). There are a few things that might be causing this, outside of the code pasted above:

  1. Calling $this->session->sess_create(); from a baseclass (or elsewhere in your class's code) would reset your session.
  2. Try combining your set_userdata calls to one call by passing it an array.
  3. Make sure your data does not have any unexpected characters in it (this can cause issues in certain browsers).
  4. Make sure your session class settings in the config are not rolling over the cookie every request.

Alternatively, consider an alternate session class like Native sessions

Bruce Alderson

related questions