CodeIgniter sessions randomly timing out

Disclaimer: This post is about cookies, not books. In fact, cookies and books do not go together – as anyone with children can attest, they tend to leave nasty little oil stains on the pages and crumbs in the gutter. (now it’s at least vaguely book related – file under “Book Care”)

I’m departing from our topic only because we were encountering problems with CodeIgniter sessions sporadically expiring and a DuckDuckGo hunt (and Google hunt, for that matter), failed to yield an easy solution and I thought I’d save others the same pain.

Many people seem to be affected by this problem judging by questions asked in forums, and the most common suspect mentioned is the use of Ajax. This seems to solve the problem for many people, but not all, and there isn’t an easy answer for the thus afflicted. However, much debugging and poking at the mess yielded a bug in how CodeIgniter handles encrypted session cookies in conjunction with xss_clean. This caused the occasional cookie to fail when being unencoded on retrieval, forcing a re-spawn of a new session.

Once I knew what to go Duck hunting for, the solution (and explanation) is to be had over at The Biz Hole, who suggests three different remedies for solving the disappearing session problem in CodeIgniter.

Leave a Reply

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