(01-11-2016, 12:02 PM)Novotmike Wrote: Hello everyone,
I'm using CI for a while now and I decided to use it for one of my semestral projects. My problem is something I haven't encountered before. I'm using sessions for login and other parts of the application and my app uses AJAX call in loop (let's say 1 minute loop) to refres data. I'm having a problem with Sessions expiring sooner than I would expect. Even when I set them to last at least a day, they expire after aroun 2 mines.
I googled a little bit and found that this was some kind of bug back in CI2 and that it was fixed. However I did not find very much about this topic considering CI3.
I'm using
Is there any way to fix this problem?
Thank you very much in advance!
-------
How the app works.:
(View AJAX avery minute) => (Controller: check if user is logged + call to a DB for data + return data and display)
Update:
No it seems that the problem is present only when "sess_time_to_update" is set to low number - like the default 300. When I set it to long period of time (say a day) the problem seems not to occur anymore.
CodeIgniter and working with Ajax calls:
1) The function in the controller must check if it is an HTTP POST request, using $this->input->post(). You can also check if it is an AJAX request using $this->input->is_ajax_request().
2) The above function will return data in text format - can be html, json or simply plain text. (This will be the response in step 4)
3) JS function you use to execute the controller's function should send HTTP POST, instead of HTTP GET. (I use jQuery .post())
4) The response received from HTTP POST can be processed to can determine whatever action to be done.
5) On Ajax calls, do a call to $this->session_write_close();
PHP Code:
if ($this->input->is_ajax_request())
{
$this->session_write_close();
}
else
{
// Normal call
}
Yoou may need to do the $this->session_write_close(); before the Ajax check.
Hope that helps.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )