Welcome Guest, Not a member yet? Register   Sign In
CI sessions and AJAX
#11

[eluser]vickel[/eluser]
No, last_activity should be set automatically by the CI session class, shouldn't it?
#12

[eluser]vickel[/eluser]
Just one more thought: Maybe, as we are talking AJAX calls, which are asynchronyious, the session cookie is updated correctly, but the way to access it is wrong? As I mentioned earlier, with synchronoius calls, everything is fine.
#13

[eluser]Ochetski[/eluser]
Yes, last_activity is set automatically, but you can find this at CI user guide:

Note: Session cookies are only updated every five minutes by default to reduce processor load. If you repeatedly reload a page you'll notice that the "last activity" time only updates if five minutes or more has passed since the last time the cookie was written. This time is configurable by changing the $config['time_to_update'] line in your system/config/config.php file.


I think this will solve =D
#14

[eluser]vickel[/eluser]
I know about that setting and I'm having $config['sess_time_to_update'] = 10; (which is 10 seconds) I've read all the post and threads and wikis for the last 3 days, but I didn't find an answer, that's why I'm posting this issue.
I'm pretty sure it has to do with the AJAX calls.
#15

[eluser]Ochetski[/eluser]
Hm... instersting.
I will try some tests today, and post you if I got some answer.
#16

[eluser]vickel[/eluser]
OK thanks a lot.... If I find something new, I'll post it here
#17

[eluser]vickel[/eluser]
Ok, I came to the conclusion, that loading page "b" from within page "a" with Ajax (calling a CI controller function) updates the CI session cookie. But this CI session cookie values are only accessable in page "b" and not in page a. This is asynchronious behaviour. I write the CI session cookie value in a hidden div in page b which then can be read by a script from page a.

Hope this helps somone, pls. correct if I'm wrong ;-)
#18

[eluser]WanWizard[/eluser]
Not entirely sure what you're trying to say.

Every request to the server, either by the browser itself or by an AJAX request, will sent the session cookie to the server. Using this cookie, CI can relate the request to the correct session. When the answer is sent back to the browser (or the AJAX request), the cookie is sent back with it, in the HTTP header. So both requests (what you call page 'a' and 'b', what I assume to be different controllers) will have access to the same session information.

Offcourse, controller 'a' won't know anything about what controller 'b' is about to do, since it executes after 'a' was finished. I don't understand what you mean with 'writing a cookie value in a div'. You mean session variable? If I understand you correctly 'b' results in an AJAX response to a script in the page generated by 'a'. So naturely scripts in 'a' will have access to whatever result was sent back...
#19

[eluser]theshiftexchange[/eluser]
Are you saying in your original post that when you do an AJAX call you lose the session?

If so - there are lots of solutions to that problem on the forums - just search for AJAX & Session. WanWizard has posted a few updates to the session file that solves this (and other) problems.




Theme © iAndrew 2016 - Forum software by © MyBB