Skip to content
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

Cannot change session id when session is active warning - after upgrade from PHP 7.2 to 7.4 #26

Open
jorgeribeiro opened this issue Aug 18, 2021 · 1 comment
Labels

Comments

@jorgeribeiro
Copy link

jorgeribeiro commented Aug 18, 2021

BC Break Report

Q A
Version 1.7.2 and 1.9.0

Summary

After upgrading my project from PHP 7.2 to 7.4 all requests done in my application return this warning. The warning is triggered in the file PhpSessionPersistence.php, on the first line of the method startSession, when session_id($id) is called. I tried to upgrade the package to the version 1.9.0, but the error persists. There is a similar bug reported regarding the session_name function and apparently it was introduced in PHP 7.2, but I never had any issues before the upgrade to PHP 7.4. I've done a lot of research about this issue but I couldn't find a proper solution, that's why I decided to open this issue. I found very odd that no one else reported it, so I decided to give it a shot.

I found two ways to bypass this problem:

private function startSession(string $id, array $options = []) : void
{
    @session_id($id); // Ignore the warning
    session_start([
        'use_cookies'      => false,
        'use_only_cookies' => true,
        'cache_limiter'    => '',
    ] + $options);
}

== OR ==

private function startSession(string $id, array $options = []) : void
{
    if (!session_id()) { // Check if session is already set beforehand
        session_id($id);
    }
    session_start([
        'use_cookies'      => false,
        'use_only_cookies' => true,
        'cache_limiter'    => '',
    ] + $options);
}

I ran the tests using the versions 1.7.4 and 1.9.0 with PHP 7.4 and they were successful.

@zoeurk
Copy link

zoeurk commented Aug 26, 2023

it's seems that :

if(session_id() == "")

is better than:

if(!session_id())

source: PHP session_id Manual

Inchie added a commit to Inchie/mezzio-session-ext that referenced this issue Oct 27, 2023
mezzio#26
Fix provided by https://github.com/jorgeribeiro

Signed-off-by: Timo Nußbaum <timo.nussbaum@gmx.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants