CodeIgniter Forums
Session will not persists in CI 3.1.11 with CI Rest Api, no matter what I do - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Session will not persists in CI 3.1.11 with CI Rest Api, no matter what I do (/thread-75212.html)



Session will not persists in CI 3.1.11 with CI Rest Api, no matter what I do - deltatangodt - 01-12-2020

I cannot get my session to persist past the login.

I can see the session data in the sessions folder, the variables are saved. When a user logs in I am saving their user id and company id in the session.

But once I navigate to another page in my ReactJS project, and do another ajax call, the CI Rest API just returns unauthorized. The session token also changes.

I noticed this bug when I went from 3.1.10 to 3.1.11. But I am not honestly sure what is causing it and what to do.

I have spent 4 hours reading blogs and forums trying all the suggestions I could find and understand; nothing is resolving this.

$config['sess_driver'= 'files';
$config['sess_cookie_name'= 'ci_session';
$config['sess_expiration'= 7200;
$config['sess_save_path'= APPPATH . 'sessions';
$config['sess_match_ip'= FALSE;
$config['sess_time_to_update'= 300;
$config['sess_regenerate_destroy'= FALSE;


$config['cookie_prefix']    = '';
$config['cookie_domain']    = '.localhost:4011';  // running dev project on my laptop
$config['cookie_path']      = '/';
$config['cookie_secure']    = FALSE;
$config['cookie_httponly']  = FALSE;


Yes I have sessions autoloaded.

This was all working and then it just stopped after 3.1.11.


RE: Session will not persists in CI 3.1.11 with CI Rest Api, no matter what I do - jreklund - 01-13-2020

.localhost:4011 = Not a valid domain.

Use 'localhost' (becomes .localhost), '.localhost' or NULL (becomes localhost).


RE: Session will not persists in CI 3.1.11 with CI Rest Api, no matter what I do - deltatangodt - 01-14-2020

(01-13-2020, 11:52 AM)jreklund Wrote: .localhost:4011 = Not a valid domain.

Use 'localhost' (becomes .localhost), '.localhost' or NULL (becomes localhost).
Thanks, I changed this but I still have the same problem. As soon as I log in, when I try another ajax request it says I am unauthorized. By the time log in occurs, the session has regenerated 4 times on 1 single request.

Also the garbage collection never seems to happen, session files just pile up.


RE: Session will not persists in CI 3.1.11 with CI Rest Api, no matter what I do - InsiteFX - 01-14-2020

When finished with session data you need to do a session write close when using Ajax.