• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
different cookie handling IE vs. firefox/chrome/safari

#1
[eluser]kbroich[/eluser]
Hi guys,

I am starting with Codeigniter and I am not sure if my issue has something to do with CI or if it is a general misunderstanding of HTTP.

The thing that confuses me is that a login process leads to different results in Internet Explorer vs. Safari/Chrome/Firefox.

Please take a look at the demo (You can enter whatever u want in the form)

What am I doing?

I render a form which takes an email and a password and creates a new user:
Code:
$this->exampleuser->create($this->input->post('email'), $this->input->post('password'));

I also set a cookie to make sure that I am able to see that the user is already logged in when the page is refreshing or he/she comes back.

Code:
setcookie('loginstatus', TRUE);

After that I redirect to the start page

Code:
redirect('stream');

to see if the user is logged in or not:

Code:
if ($this->exampleuser->isloggedin() == TRUE) {
  echo "The user is already logged in";
  $this->load->view("v_stream_start");
} else {
  echo "The user still has to login";
  $this->load->view("v_stream_login");
}

In FF/Chrome/Safari it works without problems. But for some reason the Internet Explorer has trouble retreiving the cookie in the
Code:
$this->exampleuser->isloogedin()
method.

In there I do nothing more than
Code:
public function isloggedin()
{          
   return $this->input->cookie('loginstatus');
}

When I var_dump the retreived cookie in Internet Explorer it says bool(false) while in all other browsers there's a "1" in there.

Does anybody have an idea what part I am missing?

Thank u all in advance!



#2
[eluser]InsiteFX[/eluser]
in your ./application/config/config.php make sure the cookie name does not have an underscore ci_sessions in it cisessions.

#3
[eluser]kbroich[/eluser]
Thanks for the hint... I changed that but it did not help..

I was reading a bit. Some people had the same issue when the server time was not correct. I had my server running 1 minute late - updated but still does not work.

In the meantime I use PHP native cookie commands but it still doesn't work... What the hell is wrong with this...

Is it possible that this
Code:
redirect()
function has something to do with it? When I comment this redirect command I can see that the cookies in IE get set. But after the redirect they are gone unlike Firefox/Chrome/Safari...

Wow check the demo - when I don't use the redirect command IE can set the cookie but FF/Chrome/Safari don't!!! I am totally confused by now...

#4
[eluser]InsiteFX[/eluser]
Well check your IE cookie settings, IE has default cookie restrictions like not allowing session cookies.

1) IE menu click on Tools button then Internet options.
2) Click on the Privacy tab then click on the Advanced button.
3) Check the Override automatic cookie handling.
4) First-party Cookies Accept.
5) Third-party Cookies Accept.
6) Check the Always allow session cookies.

I use CI Sessions and cookies with no problems.

#5
[eluser]kbroich[/eluser]
Thanks for the help but unfortunately this was not the solution. I still think it is something with the redirect() and maybe also with retreiving cookies in the ci_model subclasses...

EDIT:

Everything runs as expected until I call the redirect() method - after that IE somehow can't retreive the cookie while all other browsers can Sad

Additionally I opened this thread here:

http://stackoverflow.com/questions/11319...ork-in-ie9


Well in the meantime I found out that coding it without CI is working in Internet Explorer so it has to be some configuration thing with CI and cookies. I will look for some bug report possibility....

#6
[eluser]Aken[/eluser]
First, try not to intermingle raw PHP w/ CodeIgniter functions, as CI will often add its own proprietary code on top of PHP. Just look at the set_cookie() method in the Input class.

Second, after you switch to using all CI code (what I would recommend), verify your cookie settings in your config file. Make them as basic as you can - use just lowercase letters, make sure the cookie domain and such is accurate.

I don't have IE so I can't completely test anything, but I would start there. I'm guessing there is a setting somewhere that IE treats somewhat differently that is being confused due to the inconsistent use of CI vs. PHP. Give it a shot, see if anything changes.

#7
[eluser]kbroich[/eluser]
Thanks for helping out ... I found out that actually the redirect and cookie retreiving works as long as you don't redirect to the same controller you came from.

So when you redirect to a subroutine like redirect('controllername/dosomething); and there then try to check the cookies everyhting is working in IE as well. But when you redirect to the index-function of the controller like redirect('controllername'); IE is not on your side...

Makes sense?

#8
[eluser]Aken[/eluser]
That still seems odd. It shouldn't matter where you redirect to, as long as the page loads and the cookie is set up properly.

#9
[eluser]InsiteFX[/eluser]
Also you need to keep this in mind when trying to view cookies.

The data from the cookie won't be available until the next page request.

#10
[eluser]kbroich[/eluser]
But a redirect is a request, isn't it?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.