Replacing CodeIgniter’s session by PHP’s Native Session


codeigniterFor last 8 months, I have been working on a web application. We are developing the application based on CodeIgniter framework. In our project there are normal web version and mobile view version. Some days ago we noticed that, some people can’t login their account via mobile version though there username & password are correct. After debugging and digging the problem we found that in iPod Touch 2G/3GS Safari browser, this problem is happening.

We are using CodeIgniter’s built in session library and that is different than normal PHP’s session. We found that for each visit of the user, the server can’t track the session and regenerating new session id each time. Very weird situation for us. As we coded all over based on CodeIginter’s session library’s function so its not optimal solution for us to remove the codes and use PHP’s native session. Because in that case there is high possibility to generate new bugs. After lots of searching in the net at last we found a wrapper class for CodeIgniter.

This wrapper class is named Native session . It uses the same functions name like CodeIgniter’s Session class, but it used PHP’s native session on the back end. As our project is running on Dedicated Server so we are not worried about the session security. We replaced CodeIgniter’s Session class by this Native session  class and it solved our problem.

So if you’re facing this type of session related problem by using CodeIgniter’s Session library, you can use the  Native session library to fix the problem. Hope it helps.

mahmud ahsan

Love computer programming and write occasional blog post. In my early career I worked mostly on web based application and since 2011, I exclusively working on iPhone and android applications. I work at home, father of a nice kid and husband of a beautiful wife. [My Business | Twitter | Linkedin]

You may also like

9 Comments

  • M.M.H.Masud
    August 24, 2011 at 12:56 am

    Nice one. Very much helpful. i keep this in my bookmarks.

  • Manoranjan
    August 24, 2011 at 4:07 pm

    I need code as facebook like button. So that a users clicks the button and logins, then he will be able to hit a count and like. So in similar way i need a button code. If anyone is interested, please let me know. m.badajena@gmail.com

  • Nithin K Varrier
    December 7, 2011 at 4:35 pm

    Thanks Ahsan. Very helpful article. I’m facing the same problem. thank you so much

  • Carlson Orozco
    December 25, 2011 at 10:40 pm

    I got the same problem… Thanks Ahsan for this article.

  • andre3
    February 9, 2012 at 5:15 am

    Thank you 😀 saved me alot of problems hehe

  • incaib
    May 23, 2012 at 4:55 pm

    Hello, when you use the session of #Codeigniter? save the sessions in a db mysql ? I need any friend with iPod Touch 2G/3GS Safari browser for test a login form. Thank’s my twitter is @incaib actually developing with CodeIgniter, Sorry my english.Good article interesting.

  • Victor
    July 19, 2012 at 12:37 pm

    Hi,

    How do I get the session data to be stored to the session table in my database?

    It doesn’t look like the Native session class checks the config for this value:
    $config[‘sess_use_database’] = TRUE;

    So does this mean it doesn’t support saving to database?

  • jnikolakisJ.Nik
    September 22, 2012 at 12:59 pm

    Maybe you would like to update the links to the native session to the newest url: https://github.com/EllisLab/CodeIgniter/wiki/Native-session

  • Clain Dsilva
    February 15, 2014 at 11:46 am

    Thanks mate, I have been in a research to handle CI sessions. Your post shed lots of light to my hunt ..!!!

Comments are closed here.

About Me

Hi I am Mahmud Ahsan. I Love computer programming and write occasional blog post. In my early career I worked mostly on web based application and since 2011, I exclusively working on iPhone and android applications. I work at home, father of a nice kid and husband of a beautiful wife. [My Business | Twitter | Linkedin]

Twitter Feed

Fanpage