Welcome Guest, Not a member yet? Register   Sign In
sessions don't seem to be working
#1

[eluser]bevans[/eluser]
I have a new site with at login page.
When someone logs in a session should be set with the person's name as one of the session variables. If the variables are set as shown in the code below I allow the person to view stuff that only a person who is logged in can see.

The session works fine in FireFox... A person can login with no problem, but Internet Explorer (IE 7 or IE 8) does not work. Why would sessions work in FF but not IE? Any ideas for what I should check into?

The session library is auto loaded in the autoload.php file.

Here is the code that should do the trick:
Code:
$session_data = array(
    'logged_in' => 'Yes',
    'profile_id' => "$profile_id",
    'first_name' => "$first_name",
    'access' => "$accesslevel"
        );
$this->session->set_userdata($session_data);


And this is the code that should check to see if they session is good and if the person is logged in:
Code:
if(($this->session->userdata('logged_in') == 'Yes') && (($this->session->userdata('access') == 'user') || ($this->session->userdata('access') == 'admin')))
      {
          return true;
      }
          else
{
return false;
}

Thanks in advance,
Branden
#2

[eluser]überfuzz[/eluser]
[quote author="bevans" date="1254036933"]...
Code:
if(($this->session->userdata('logged_in') == 'Yes') && (($this->session->userdata('access') == 'user') || ($this->session->userdata('access') == 'admin')))
      {
          return true;
      }
          else
{
return false;
}

Thanks in advance,
Branden[/quote]

I've seen this subject in the forum. Try searching for it.

Off topic: You could/should/would change the access-status and UserId to integers.




Code:
if($this->session->userdata('logged_in') == TRUE ) //or FALSE
     if($this->session->userdata('logged_in') == 1 ) // or 0

     if($this->session->userdata('access') == 1)) // still simple to have different levels.
     if($this->session->userdata('access') == 2))
#3

[eluser]ggoforth[/eluser]
Don't quote me on this, but I knew of someone else that was having trouble with this. He said it was because of the way CI handles sessions, it stores all the data in a string in a cookie on the client side. There was something wrong with the way IE 7 and 8 were handling this string, and as such we could not use CI sessions. We went with a third party CI database class that ended up working VERY well. Again, I am not an expert, but this is a common problem that I've heard.

Greg
#4

[eluser]bevans[/eluser]
[quote author="überfuzz" date="1254051776"][quote author="bevans" date="1254036933"]...
Code:
if(($this->session->userdata('logged_in') == 'Yes') && (($this->session->userdata('access') == 'user') || ($this->session->userdata('access') == 'admin')))
      {
          return true;
      }
          else
{
return false;
}

Thanks in advance,
Branden[/quote]

I've seen this subject in the forum. Try searching for it.

Off topic: You could/should/would change the access-status and UserId to integers.




Code:
if($this->session->userdata('logged_in') == TRUE ) //or FALSE
     if($this->session->userdata('logged_in') == 1 ) // or 0

     if($this->session->userdata('access') == 1)) // still simple to have different levels.
     if($this->session->userdata('access') == 2))
[/quote]


Thanks for the info and suggestion to change to integers rather than strings.

As for this topic... I had searched, but not found anything that was actually the same. Some things were similar, but not quite covering the problems. I will search again though.
#5

[eluser]bevans[/eluser]
[quote author="ggoforth" date="1254054931"]Don't quote me on this, but I knew of someone else that was having trouble with this. He said it was because of the way CI handles sessions, it stores all the data in a string in a cookie on the client side. There was something wrong with the way IE 7 and 8 were handling this string, and as such we could not use CI sessions. We went with a third party CI database class that ended up working VERY well. Again, I am not an expert, but this is a common problem that I've heard.

Greg[/quote]

Greg,

Thanks for the suggestion about going with a third party CI db class. I will see if I can find one... as of now, I have not searched, but will do that tomorrow.

Branden
#6

[eluser]bigtony[/eluser]
You could try the [url="http://codeigniter.com/wiki/Session_Hybrid/"]Session Hybrid[/url] library.
#7

[eluser]bevans[/eluser]
[quote author="bigtony" date="1254229177"]You could try the [url="http://codeigniter.com/wiki/Session_Hybrid/"]Session Hybrid[/url] library.[/quote]

Thanks for pointing me to the hybrid session. It looks good. I will use it and see how it works for me.

Branden
#8

[eluser]bretticus[/eluser]
[quote author="ggoforth" date="1254054931"]Don't quote me on this, but I knew of someone else that was having trouble with this. He said it was because of the way CI handles sessions, it stores all the data in a string in a cookie on the client side. There was something wrong with the way IE 7 and 8 were handling this string, and as such we could not use CI sessions. We went with a third party CI database class that ended up working VERY well. Again, I am not an expert, but this is a common problem that I've heard.[/quote]

You might try setting up database sessions (very easy to configure) or encrypting your cookie data (also a config.php one liner.)

Be aware, cookies can only hold up to 4k (not that you are anywhere close.)

Or, if that doesn't work, you could try and use real PHP sessions (I guess that is what Session Hybrid does.)

Good Luck!
#9

[eluser]Bikun[/eluser]
Is it possible to use native PHP $_COOKIE with Session Hybrid? Actually I have tried to use cookies with native Codeigniter Session class, but it deletes all my cookies.

What I try to do is:
$expire=time()+60*60*24*30;
setcookie("user", "Alex Porter", $expire);

When I run the following right after setting cookie, it works well:
print_r($_COOKIE);
break;

If I remove break and let page refresh, $_COOKIE has only the following:
Array
(
[PHPSESSID] => gqu9g68nrucsgoodn2ode4c6v7
)

session class is in autoload.php.




Theme © iAndrew 2016 - Forum software by © MyBB