Welcome Guest, Not a member yet? Register   Sign In
Issue with session library stored in database, upgrading from CI 1.7.2 to 2.1.
#1

[eluser]enrico.simonetti[/eluser]
Hi Guys,

I'm posting this, so that people will not spend time debugging this issue, as I did.

I've finally upgraded from a website with Codeigniter 1.7.2 to 2.1.
I was using the session library, storing session data inside the database.

The sessions were not working at all.
On every hit of the same page, there was a new session entry inside the database.
Switching back to cookies only, everything worked fine.
Switching back to database again, it was not storing the sessions.

Apparently my old sql table definition (v1.7.2) had a user_agent column of length varchar(50).
Looking at the code on the session library version 1.7.2 the user agent checking code was different from version 2.1.

On version 1.7.2 the code is comparing the first 50 chars of the user's user agent, against the database value (50 chars), while the code on version 2.1 does not limit the user agent's length, so in my case was comparing a really long string, against a 50 char string, failing all the time.

To fix that, it was just a matter of either enlarge the "user_agent" column or change the data type to "text".

Personally I prefer to change the column type to text, so that any user agent will fit (alter table ci_sessions modify user_agent text not null) and after that, the session library started working again.

Hope this helps!






Theme © iAndrew 2016 - Forum software by © MyBB