Welcome Guest, Not a member yet? Register   Sign In
Session data lost after redirect randomly (CI4.1.5)
#11

Found this on stackoverflow:

PHP session lost after redirect
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#12

(06-22-2023, 10:33 PM)InsiteFX Wrote: Found this on stackoverflow:

PHP session lost after redirect

In CI redirects are performed under return statement, so not sure if adding exit(); after return would give any result. Additionally, in our system session is lost not after redirect, but simply by browsing through pages - not when redirect happens. Additionally, it's heavy on json requests to pull data - I suspect that it might be related to that, but I didn't get a chance to find exact flow when session disappears (as I mentioned - it happens randomly: one time page X kicks me out of the system, next time X page loads fine but page Y kicks me out).
Reply
#13

(This post was last modified: 06-23-2023, 03:38 AM by kenjis.)

If you use Ajax, do you set the request header X-Requested-With?
https://codeigniter4.github.io/CodeIgnit.../ajax.html
Reply
#14

(06-23-2023, 01:17 AM)kenjis Wrote: If you use Ajax heavily, do you set the request header X-Requested-With?
https://codeigniter4.github.io/CodeIgnit.../ajax.html

I'm not 100% sure, there is old angular v1 implementation for those. Anyway, thank you for the suggestion, I will try to add this header and will write here in some time to let you know it it helped.
Reply
#15

(06-23-2023, 01:29 AM)pJenkiss Wrote:
(06-23-2023, 01:17 AM)kenjis Wrote: If you use Ajax heavily, do you set the request header X-Requested-With?
https://codeigniter4.github.io/CodeIgnit.../ajax.html

I'm not 100% sure, there is old angular v1 implementation for those. Anyway, thank you for the suggestion, I will try to add this header and will write here in some time to let you know it it helped.

Quick update: nope, I've added that header value in ajax requests, and situation didn't change - logouts still happening.
Reply
#16

(09-27-2022, 04:16 AM)pJenkiss Wrote: When I refresh the same page (without login), every few seconds a new record is added to "ci_sessions" table.

Note: not every refresh creates new record, it happens randomly. Sometimes it creates it every refresh, sometimes it's the same for minute or so (random time, random amount of refreshes)

The behavior seems to be very strange.

There should be one record for one valid session, and the primary key constraint in the session table
(https://codeigniter4.github.io/CodeIgnit...rimary-key)
should assure that there is only one record.
Reply
#17

(06-30-2023, 06:57 PM)kenjis Wrote:
(09-27-2022, 04:16 AM)pJenkiss Wrote: When I refresh the same page (without login), every few seconds a new record is added to "ci_sessions" table.

Note: not every refresh creates new record, it happens randomly. Sometimes it creates it every refresh, sometimes it's the same for minute or so (random time, random amount of refreshes)

The behavior seems to be very strange.

There should be one record for one valid session, and the primary key constraint in the session table
(https://codeigniter4.github.io/CodeIgnit...rimary-key)
should assure that there is only one record.
Records are unique - each new record has a different key. It seemed like session would be turned off in the browser, but it can't be true. Table' keys are correct. Anyway, that's not a big issue anymore - I manually turned off session in our public pages because that caused a crazy growth of sessions table (that was our biggest concern). Right now the growth slowed down because we use session for internal users only, but another issue exist - the session randomly shuts down and users randomly get kicked-off from the site. I'm unable to replicate when exactly it happens - it's always on different page, can't catch any pattern. That's why this issue is so confusing to me, I have no idea what to do and appears nobody on this forum can help as well. 

PS: for example, this is sessions table locally, I logged in to the system and opened 7 pages, made some page refreshes. 3 records appeared - checked after each click - sometimes only timestamp changes, and sometimes new records is created. All pages are the same "type": loading page + load extra data with jQuery (as I mentioned earlier - X-Requested-With header is added for those).
[Image: ci-session.jpg]
Reply
#18

(This post was last modified: 07-02-2023, 06:13 PM by kenjis.)

Another session record for a visitor is created only when the session id is regenerated (300 seconds by default).
You have three records and the all timestamps are too close. So it does not seems because of the session id regeneration.
Reply
#19

Can you please post your table schema with all fields and keys here so we can see it.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#20

(07-02-2023, 09:39 PM)InsiteFX Wrote: Can you please post your table schema with all fields and keys here so we can see it.

Here you go:
[Image: ci-session-schema.jpg]
Reply




Theme © iAndrew 2016 - Forum software by © MyBB