Monday, February 9, 2015

[CodeIgnitor][Resloved] Cannot get user_data from database session

I have visited the page in stackoverflow many times but never aware this is the solution works for me. Really thanks so much for vlad.

There is my story:
I was using this table to store the session data:

Since I cleared all my session record in database, I visited 2-3 page, ci generated around 23 records.


However, I can’t get the userdata I set in session.




And after many test and tried many method, found as vlas mentioned , my user_agent in database table is not long enough to store the user agent, some string was trim and cannot be recorded.


So the solution is using sql to change the length of user_agent column.
ALTER TABLE ci_sessions
CHANGE COLUMN `user_agent` `user_agent` VARCHAR(200) NOT NULL;

And then the user_agent is recorded is not "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (K" anymore, it's "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36"now and the session feature works really nice!

Reference:
http://stackoverflow.com/questions/2438835/codeignitor-is-generating-multiple-sessions-in-the-database-why

No comments :

Post a Comment