Codeigniter Session Problem in IE

Have you ever fall in the problem with Codeingniter Session even for simple login? I think you have, if your client use Internet Explorer. I faced the problem many times and very tired to solve that problem but could not solve it for many times. I used DB for managing session also but no luck. Later I found the problem.

Then I found that the problem is not of the session class of Codeingniter but it is the problem of IE.  CI’s session library creates standards-compliant cookies that work reliably on all web browsers except for Internet Explorer 6,7,8 and so on.  The reason being, Internet Explorer doesn’t follow standards (link).  Shame on IE !

The simple Solving is following:

Check your setting in Config:

–  Examine your cookie settings in /application/config/config.php A CI vetran recomended removing underscores from the cookie name (link). This can be done by changing:

$config['sess_cookie_name']        = 'ci_session';

to
$config['sess_cookie_name']        = 'cisession';

Also remove any underscore in $config[‘cookie_prefix’] since it is prefixed to the cookie name.

Check Your Server’s Time and Timezone:

Make sure your server’s time is correct. All browsers set cookies based on the client’s time.  IE on the other hand, goes by server time.  If the server’s time is in the past, cookies will expire as soon as they are set thus giving the illusion that your cookie never arrived.

If you are going to start a new project:

Don’t use CI’s session class.  Just write code like you normally would outside of the CI framework.  Meaning: use PHP’s native session handling functions like session_start(), unset(), session_destroy() and the $_SESSION superglobal.

– By default, PHP stores data on the server in a world-readable location, like “/tmp”.

If you must need to use Ci Session:

Go for the following class:

http://codeigniter.com/wiki/Dariusz_Debowczyk%27s_Session_Class/

Directions for how to install the class in your application are also on the above wiki page.  It needs to be improved.  Hopefully you, the reader, can improve it over time.  If you do end up improving it, please reply to this post with your updated code.

Happy Coding!

Cheers !

Advertisements

, , , , ,

  1. #1 by Phil on January 6, 2011 - 3:12 AM

    Thank you!!! the IE problem with codeigniter sessions had me scratching my head. The underscore tip did the trick.

    • #2 by Rashedul Islam Sumon on January 6, 2011 - 3:23 AM

      It was also scratching my head 🙂

  2. #3 by ricky on March 7, 2011 - 10:43 PM

    Thanks. i will try this one.

  3. #4 by ricky on March 7, 2011 - 10:45 PM

  4. #7 by Hemoptysis Heart on April 21, 2011 - 9:19 AM

    I solve this problem like this.

    in callback :

    $s = $this->facebook->getSession();
    $this->session->set_userdata("facebook_session", $s);

    to use api :

    $s = $this->session->userdata("facebook_session");
    $this->facebook->setSession($s);

  5. #8 by business cards on June 20, 2011 - 8:54 PM

    Thanks, got me out of a hole

  6. #9 by Dan on November 23, 2011 - 3:40 PM

    Thank you for your post, it helped me out nicely – I am shocked this is the default! IE never fails to annoy me! Thanks again.

  7. #10 by rudejason on January 29, 2012 - 6:57 PM

    Thanks,

    This was also an issue for me using FF 8.0.1 on Mac Lion 10.7.2 So guessing it is not just an IE issue, as it was not working in safari or chrome for me. Spent about 4 hours debugging code and trying to find an answer, but my session data, user and flash data was not saving.

  8. #11 by Sayn on February 1, 2012 - 6:04 PM

    Don’t know but can anyone tell me why we are getting this issue? I tested it on local and server. On local it is working in IE8 but on server it isn’t.

  9. #13 by soleguia on February 16, 2012 - 3:18 PM

    Hi! This article just had saved me, I was about to go nuts with this problem.
    I really want to say thanks, and if you don’t have any objection I’m going to publish a translation to spanish of this in my blog for anyone else who could need this solution.

    Thanks again.

    • #14 by Rashedul Islam Sumon on February 16, 2012 - 3:33 PM

      My pleasure! No problem, Go ahead! Post your link here so that I can see that 🙂

  10. #15 by soleguia on February 16, 2012 - 3:47 PM

  11. #16 by Ronald on April 2, 2012 - 5:05 PM

    Thanks, the server date saved me heaps!

    Cheers!

  12. #17 by Yann Laviolette, ing. on October 17, 2012 - 6:44 AM

    Wonderful!!! Removing the _ in the cookie name resolve my problem!!! You can’t know how many time you save me. I was getting random error with IE and Sessions. Seems to work now!

  13. #18 by Cho Hyun on May 23, 2013 - 4:59 PM

    Set up
    1. <!–[if IE]><meta http-equiv=”X-UA-Compatible” content=”IE=9″><![endif]–>
    service page nothing or all
    2. or
    $config[‘sess_cookie_name’] = ‘cisession’;
    $config[‘sess_match_useragent’] = FALSE;

    Why IE problem because of the ability to change the Browser Mode is so. Useragent be changed like caused.

  14. #19 by revida putri on October 7, 2014 - 6:12 AM

    After checking out a handful of the blog posts on your blog, I really
    appreciate your technique of writing a blog. I added it to my bookmark site list and will
    be checking back soon. Please visit my website as well and
    tell me how you feel.

  15. #20 by acheter kamagra en ligne on November 5, 2014 - 2:21 PM

    Hello friends, nice post and good urging commented here, I am in fact
    enjoying by these.

  16. #21 by rak gudang on November 15, 2014 - 9:30 AM

    Thanks forr the good writeup. It in truth used tto be a amusement
    account it. Glance advanced to more delivered agreeable from you!
    By the way, how could we be in contact?

  17. #22 by mtb blog on December 16, 2014 - 9:33 PM

    Interesing article. I genuinely enjoy your style of writing

  18. #23 by Die Jobbörse für Akademiker on January 22, 2015 - 8:09 AM

    I blog frequently and I truly appreciate your content.
    Your article has truly peaked my interest. I will bookmark your blog and keep checking for new details about once a week.
    I subscribed to your RSS feed as well.

  19. #24 by Gavin Lovegrove on February 10, 2015 - 2:14 PM

    Yep .. fallen into that trap as well .. built an education application for high schools (which tend to use IE as first cab off the rank) .. and CI session issues immediately became apparent! I switched to stock standard PHP session_start() etc … solved the problem straight away.

  20. #25 by tas seminar on May 12, 2015 - 1:20 PM

    Great information. Lucky me I found your website by chance (stumbleupon).
    I have saved it for later!

  21. #26 by cetak nota on May 15, 2015 - 6:43 AM

    What’s up mates, how is everything, and what you would like
    to say concerning this article, in my view its actually remarkable in support of me.

  22. #27 by it training on December 1, 2015 - 4:23 PM

    My brother suggested I might like this web site. He used to be
    entirely right. This post actually made my day. You can not believe
    simply how much time I had spent for this information! Thank you!

  1. Internet Explorer Cookie Problem | My Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: