New Session Cookie Created on Every Page Refresh in CodeIgniter

CodeIgniter’s way of handling session data is slick, and I use it a lot. However on my current project, I went overboard on my configuration changes and accidentally caused a problem that had me scratching my head for a few minutes. I noticed that session data wasn’t persisting and that my sessions table (I opted for database storage of my session data) was filling up with new rows of session data every time I reloaded a page in my project. This prevented my login functionality from working.

The solution to my problem was a configuration detail. I had set $config[‘cookie_domain’] to the domain name I will eventually use for the site. CodeIgniter didn’t like this because my development environment is not on that domain. So it was creating new cookie/session data every time I loaded a page. The problem made sense after I thought about it for a bit. I remembered that I had set a few extra settings in the config, and sure enough, that was the winner.

The problem can happen when other settings are incorrect as well. So pay close attention to those settings, and look there first if you notice that sessions are being created on every page load.

One thought on “New Session Cookie Created on Every Page Refresh in CodeIgniter”

  1. Hi,

    Ive got the same problem, but as far as I see my conf is correct, any other reason that would be causing this problem??

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.