Losing session user_data randomly |
[eluser]Unknown[/eluser]
I've searched through these forums pretty extensively but haven't managed to find something that's exactly the same as my problem or that helps me fix it. I'm running into an issue where I'm losing the information stored in the user_data column of my db for the current session. The flow is this; User attempts to log in -> Controller updates the session via Ajax call and responds to the calling page -> If the log in was successful then javascript redirects to the 'logged in' page. The problem I'm having is about 1 in 5 times this flow happens, the user ends up at the logged in page but with no data set in the user_data for the session - which essentially makes that user logged out even after successfully logging in. This is not an issue due to underscores in the session cookie name (there aren't), it's not limited to a single browser (seen in FF, IE and Safari independently). I implemented logging in the controller that's called for signing in and the page that's redirected to. The logging happens at the end of the sign in controller and the beginning of the redirected page's controller. The logging shows that session_id, ip_address, user_agent, last_activity all stay consistent. The user_data that is logged at the end of the sign in controller is lost after the redirect (the data is empty). This problem does not happen every time. I can log in 10 times in a row succesfully then randomly twice in a row it will fail. Like I said... maybe 1 in 5 is the average failure rate. Any ideas? I'm sure it's something glaringly obvious but I really don't know where the session data could be being reset since I don't know what's happening between the two steps server side (ending one controller, then being redirected to a new one through javascript on the front end). Thanks for any input!
[eluser]InsiteFX[/eluser]
application/config/constants.php Code: // Define Ajax Request application/libraries/MY_Session Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); InsiteFX
[eluser]Unknown[/eluser]
As much as I wish this was the case, adding or removing the functionality you're suggesting makes no difference whatsoever to this issue. I should have mentioned I'd already tried implementing that after browsing these forums. Thanks for the input though ![]()
[eluser]WanWizard[/eluser]
Database sessions? Cookie sessions? Alternative session library?
[eluser]ray023[/eluser]
[quote author="suicidalandroid" date="1286527399"] ...Any ideas?[/quote] I have an idea because I've been chasing a similar problem the past couple of days. Are you setting session values to the use the database: Code: $config['sess_use_database'] = TRUE; If so, the value in your user_data field might be going over the field's limit; which will cause CI to destroy the session var (See Saving Session Data to a Database) UPDATE: Now that I've taken a closer look at my database, I noticed that I had user_data set to varchar(255) instead of TEXT ![]() You probably have paid a bit more attention to detail than I have for your issue...but I will leave this post in tact on the chance it proves helpful.
[eluser]SPeed_FANat1c[/eluser]
I have very similar problem. But it only happens when administrator is working. When admin logins then sessions userdata becomes like this: a:2:{s:8:"username";s:5:"admin";s:12:"is_logged_in";s:1:"1";} when admin start working, then userdata becomes bigges, it holds filter, offset: a:4:{s:8:"username";s:5:"admin";s:12:"is_logged_in";s:1:"1";s:19:"objektu_sar_filtras";s:10:"index_ajax";s:6:"offset";s:1:"0";} BTW session get updated this way every time ajax is called: Code: $rodymas = array('objektu_sar_filtras' => 'index_ajax', It works ok, but then at some time it randomly becomes only a:2:{s:19:"objektu_sar_filtras";s:10:"index_ajax";s:6:"offset";s:2:"12";} There isn't username and is_logged_in variable anymore. I could think maybe it becomes so when I update when call ajax by not updating username and is_logged_in variable. But then it should instatnly log out after ajax call. Edit: Found that this actually is not random. Wit the user that has not admin rights it also happens, and yet I found that user becomes not logged in after "back" button in browser is pressed. Not always, but in some controllers. But still in the ci_sessions table user is logged in, but it gets userdata that he ins't logged int. I made a test controller with function to see Code: function index() and exactly - he isn't logged in. So it means that session class thinks that user is not logged, although he is. Why could it be?
[eluser]WanWizard[/eluser]
This is a common issue when using sessions and ajax calls. Search for IS_AJAX.
[eluser]SPeed_FANat1c[/eluser]
It looks like it works now ![]() ![]() ![]() BTW there is small error in InsiteFX post - it should be Code: if ( ! IS_AJAX) not Code: if ( ! IS_AJAX())
[eluser]InsiteFX[/eluser]
DEFINE in application/config/constants.php Code: // Define Ajax Request EDITED: 11-04-2010 InsiteFX |
Welcome Guest, Not a member yet? Register Sign In |