Welcome Guest, Not a member yet? Register   Sign In
Session save handler can't see object reference
#1

Hi!
I have a very weird issue. I fear it's a PHP itself that fails here but I ran against in in CodeIgniter so someone might have more info on that.
I'm using the File session driver. I do the following:
Code:
$modifiedPerson = clone $_SESSION[ 'user' ];
// Do some stuff with $modifiedPerson and if all is good:
$_SESSION[ 'user' ] = $modifiedPerson;


All is well till the end of the index.php process.
But when I put a breakpoint to FileHandler::write() and start debugging, I see $_SESSION[ 'user' ] pointing the original object, not the reassigned clone.

PHP 7.2.34
CI 4.0.3
MacOS BigSur 11.6
Apache 2.4.46
Reply
#2

I was wrong. It's not only the $_SESSION[ 'user' ] member.

It's the whole $_SESSION[] array that somehow gets reverted to at this moment unknown previous status when in FileHandler::write()
Reply
#3

(This post was last modified: 02-18-2022, 02:40 AM by Jan Zelenka.)

Hi all,
I still can't put my finger on this but I might have some leads. It seems to be related to Filters that start the session and then return redirect.
Can anyone think of a scenario where a filter with redirect can mess up a session in the way described above?
Reply
#4
Exclamation 

Hi again. I believe I've been able to trace the issue down. In fact, I have another post here and I never realized they were connected: https://forum.codeigniter.com/showthread.php?tid=77381

The problem seems to be quite straight forward: when I use redirect(), the session is simply not written (using the FileHandler) - at least not before the redirect request kicks in. And because I have a filter that needs to check the session, it starts it and whatever was added to in in the previous call is lost.

Would anyone have a clue how I can get this fixed?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB