-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Session ID changing with custom session handler in PHP 8.2.0RC3 #9668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Many thanks! I don't think I have the ability or time to build some Windows binaries. However I can confirm that adding public function validateId($key){return true;} to my custom session handler solves the problem. And also, now that I have seen the documentation for ini_set('session.use_strict_mode', '1');
session_name('TESTING'); to my test. So it looks very much like a duplicate. Are you interested in a test program, or is it not worth it? And should my session handler have a proper implementation of |
I've found another problem, which may be another symptom of the same bug. I get the same problem (ie session_id changing each time) even if I set a custom session handler and then immediately reset it to the default session handler. See the test code below. Note that the custom session handler has a validateId() method in order to circumvent the previous manifestation of this bug. With PHP 8.2.0RC2 the program behaves as expected and gives error log output such as
But with PHP 8.2.0RC3 the session id changes each time:
Here is the test code (apologies for the infinite loop): <?php
error_reporting(-1);
class MySessionHandler implements SessionHandlerInterface, SessionUpdateTimestampHandlerInterface
{
public function __construct()
{
error_log(__METHOD__);
}
public function open($path, $name): bool
{
error_log(__METHOD__ . " $path $name");
return true;
}
public function close(): bool
{
return true;
}
#[\ReturnTypeWillChange]
public function read($id)
{
error_log(__METHOD__ . " $id");
return 'foo|s:3:"bar";';
}
public function write($id, $data): bool
{
error_log(__METHOD__ . " $id $data");
return true;
}
public function destroy($id): bool
{
error_log(__METHOD__ . " $id");
return true;
}
#[\ReturnTypeWillChange]
public function gc($max_lifetime)
{
error_log(__METHOD__ . " $max_lifetime");
return true;
}
public function validateId($key) : bool
{
error_log(__METHOD__ . " $key");
return true;
}
public function updateTimestamp($id, $data) : bool
{
error_log(__METHOD__ . " $id $data");
return true;
}
}
$handler = new MySessionHandler();
session_set_save_handler($handler, true);
$handler = new SessionHandler();
session_set_save_handler($handler, true);
ini_set('session.use_strict_mode', '1');
session_name('TESTING');
session_start();
error_log(session_id());
header("Location: " . $_SERVER['PHP_SELF']); |
@campbell-m I originally opened #9583, and what you are seeing matches with what is expected when Girgias attempted to fix the problem by simply making |
@campbell-m Lines 1070 to 1074 in e5ac246
Note how 1073 is |
@warenzema |
Indeed, that fix will only be in the next RCs (8.0.25RC1, 8.1.12RC1 and 8.2.0RC4). Anyhow, I've double-checked that #9638 fixes @campbell-m's test script, so closing as duplicate of #9583. |
I can confirm that RC4 fixes the test script above. |
Description
I'm afraid I can't yet reproduce a minimal test case after many hours of trying. However in the meantime I thought I'd report what I'm seeing anyway as we're getting close to the PHP 8.2.0 release date and in case someone can recognise what might be going wrong.
My application uses a custom session handler implementing the SessionHandlerInterface to store sessions in the database. It has worked fine with PHP 8.0, 8.1 and all the alpha, beta and RC versions up to and including RC2. Then when I installed RC3, sessions suddenly stopped working and the value of $_SESSION on one page was not the same as what had been written on the previous page. Adding some debugging I can see that the problem is that in RC3 the value of
$id
passed toread()
when the session starts is not the same as that passed towrite()
when the previous page exits. However in RC2, with the exact same code, the two$id
values are identical.Any ideas?
PHP Version
PHP 8.2.0RC3
Operating System
Windows 11 IIS
The text was updated successfully, but these errors were encountered: