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

V4 Session Doesn't Passed Between Pages/Routes #370

Open
tohizma opened this issue Dec 9, 2023 · 2 comments
Open

V4 Session Doesn't Passed Between Pages/Routes #370

tohizma opened this issue Dec 9, 2023 · 2 comments

Comments

@tohizma
Copy link

tohizma commented Dec 9, 2023

Session doesn't passed between pages/routes.
Simple test case:

    public function testpost($f3)
    {
        session_start();
        $_SESSION['globalsessiontest'] = "session from global";
        $f3->set('SESSION.f3session', 'session from f3');
        echo 'POST TEST<br>';
        echo '<form method="post" action="testrcvpost">
            <label for="inputfield">Something:</label>
            <input type="text" name="inputfield" /><br />
            <input type="submit" />
            </form>';
    }

    public function testrcvpost($f3)
    {
        session_start();
        echo 'Received:<br>';
        echo 'Global Session: '. json_encode($_SESSION).'<br>';
        echo 'F3 Session: '. json_encode($f3->get('SESSION')).'<br>';
        echo 'POST fields: '. json_encode($f3->get('POST')).'<br>';
        echo 'Received Cookies: '. json_encode($f3->get('COOKIE'));
    }

Result is:

Received:
Global Session: []
F3 Session: []
POST fields: {"inputfield":"type something"}
Received Cookies: {"PHPSESSID":"rohui88ra03rp9qikt7g47hl7m"}

Chrome Inspect shows that session is correct (match with sending page)

Cookie: PHPSESSID=rohui88ra03rp9qikt7g47hl7m;

Tested using form post and ajax post request.

Environment:
PHP Version 8.2.10
F3 version 4 dev

"name": "bcosca/fatfree-core",
"version": "v4.x-dev",
"source": {
     "type": "git",
     "url": "https://github.com/f3-factory/fatfree-core.git",
     "reference": "37c5fdcd77cfd0681df59788315b9b72bc653463"
 }

If same code tested using version 3.8 works normally

@Zenger
Copy link

Zenger commented Jun 29, 2024

I'm not sure what the cause is but the solution I found so far is not to call new Session(); and set session.auto_start = 1 in php.ini.
php will auto start sessions and you can still use normal $f3->get calls on sessions as usual, something changed in php versions and f3 has yet to catch up the session is constantly lost, I've tried memcached, db based and file based sessions they all get lost.

@tohizma
Copy link
Author

tohizma commented Jul 9, 2024

Found solution, maybe variable assignment is backward. Temporary Fix on base.php line 575

function sync(string $key): ?array
{
      //return $GLOBALS['_'.$key] = &$this->_hive_data[$key]; // original code
      return $this->_hive_data[$key] = &$GLOBALS['_'.$key]; // flip hive assignment
}

Not found any side effects yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants