PHP session: How to edit the Session / Editting Session file of another user

Currently, in my system, it is sometimes necessary for the session of other users to be updated with a new value. The current case now requires the modification of a single value in the session file of some users when a given action is performed.
In my project, I created a SessionHandlerCustom class that implements SessionHandlerInterface, and with it, I implemented logic that creates a custom session with an ID for each user. I can access the file in a custom directory, but strangely, I can not use file_put_contents nor file_get_contents for these session files. I tried to work around the session functions, and by using the read () function presented in SessionHandlerCustom, I was able to get all the contents of a user's session to help its SessionId session ID.

The method works, SessionFileGetValueByHashCode, is the one that retrieves the contents of a session and with a key (usually the name of the field I want in the file), it will get the exact string of that key with its values.
The second method, which does not work at all, is the one that will actually change the value in the session, but it just does not work. I tried to manipulate the file directly without success and I tried using the SessionHandlerCustom-> write () method but this has no effect.

Can someone help me and explain how is the right way to change / manipulate another user's session?

A system example: A common user is registered, while an administrator uses the administrator functions simultaneously and changes a value for that user. If the value does not always match a value obtained from the database, the value of the session variable of this currently logged on user must be changed.

If you are curious, the system is Open Source, and you can access it here:
https://github.com/msiqueira-dev/InfraTools

SessionFileGetValueByHashCode

// The & $ value will be populated with the $ integer key and its values ​​presented in the session file. For example: SomeValue | s: 0: "";
public function SessionFileGetValueByHashCode (& $ Value, $ Application, $ SessionId, $ Key)
{
$ Value = NULL;
if (isset ($ Application) &&! empty ($ Application) && isset ($ SessionId) &&! empty ($ SessionId) && isset ($ Key) &&! empty ($ Key))
{
$ file = SESSION_PATH. $ Application. "/ sess_". $ SessionId;
if (file_exists (($ file)))
{
$ str = $ this-> InstanceSessionHandlerCustom-> read ($ SessionId);
$ start = strpos ($ str, $ Key);
$ end = $ start;
while ($ str[$end] ! = "#";)
{
$ Value. = $ Str[$end];
$ end ++;
}
$ Value. = & # 39 ;;
$ end ++;
while ($ str[$end] ! = "#";)
{
$ Value. = $ Str[$end];
$ end ++;
}
$ Value. = & # 39 ;;
if ($ Value! = NULL)
return Config :: RET_OK;
}
}
return Config :: RET_ERROR;
}

SessionFileUpdateValueByHashCode

public function SessionFileUpdateValueByHashCode ($ Application, $ SessionId, $ OldValue, $ NewValue)
{
if (isset ($ Application) &&! empty ($ Application) && isset ($ SessionId) &&! empty ($ SessionId)
&& isset ($ OldValue) &&! empty ($ OldValue) && isset ($ NewValue) &&! empty ($ NewValue))
{
$ file = SESSION_PATH. $ Application. "/ sess_". $ SessionId;
if (file_exists (($ file)))
{
$ str = $ this-> InstanceSessionHandlerCustom-> read ($ SessionId);
$ str = str_replace ($ OldValue, $ NewValue, $ str, $ count);
if ($ count> 0)
{
echo $ str. "
"; if ($ this-> InstanceSessionHandlerCustom-> write ($ SessionId, $ str)) return Config :: RET_OK; } } } return Config :: RET_ERROR; }