Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Session problem with upgrade 1.7.3 to 1.8
  • I upgraded FuelPHP from 1.7.3 to 1.8. After migrating session is lost after redirect.

    Example:

    \Fuel\Core\Session::set('user', array('id' => 1));
    var_dump(\Fuel\Core\Session::get('user')); // returns Array
    ([id] => 1)

    // after redirect session is lost
    \Fuel\Core\Response::redirect(\Router::get('index'));
    var_dump(\Fuel\Core\Session::get('user')); // returns NULL

    My php version is 5.6.11, nginx/1.9.3 (Ubuntu).

    Thank you in advance for your help.
  • HarroHarro
    Accepted Answer
    I can't reproduce it. I took a new install (1.9/dev), replaced the welcome controller with this:

        public function action_index()
        {
            \Session::delete('user_id');
            \Response::redirect('/welcome/test1');
        }

        public function action_test1()
        {
            var_dump('1-BEFORE', $x = \Session::get('user_id', 0));
            \Session::set('user_id', ++$x);
            var_dump('1-AFTER', \Session::get('user_id'));
            \Response::redirect('/welcome/test2');
        }

        public function action_test2()
        {
            var_dump('2-BEFORE', $x = \Session::get('user_id', 0));
            \Session::set('user_id', ++$x);
            var_dump('2-AFTER', \Session::get('user_id'));
            \Response::redirect('/welcome/test3');
        }

        public function action_test3()
        {
            var_dump('3-BEFORE', $x = \Session::get('user_id', 0));
            \Session::set('user_id', ++$x);
            var_dump('3-AFTER', \Session::get('user_id'));
        }

    with this as a result, which looks very correct to me?

    APPATH/classes/controller/welcome.php:38:string '1-BEFORE' (length=8)
    APPATH/classes/controller/welcome.php:38:int 0
    APPATH/classes/controller/welcome.php:40:string '1-AFTER' (length=7)
    APPATH/classes/controller/welcome.php:40:int 1

    APPATH/classes/controller/welcome.php:46:string '2-BEFORE' (length=8)
    APPATH/classes/controller/welcome.php:46:int 1
    APPATH/classes/controller/welcome.php:48:string '2-AFTER' (length=7)
    APPATH/classes/controller/welcome.php:48:int 2

    APPATH/classes/controller/welcome.php:54:string '3-BEFORE' (length=8)
    APPATH/classes/controller/welcome.php:54:int 2
    APPATH/classes/controller/welcome.php:56:string '3-AFTER' (length=7)
    APPATH/classes/controller/welcome.php:56:int 3

  • p.s. NEVER use direct references to \Fuel\Core classes! Always use the aliased version, otherwise core class extensions will go very wrong...
  • I figured it out! I had 1.8 version. After I switched to dev-1.9/develop session works fine.

    My composer.json when session didn't work:
    ...
        "require": {
            "php": ">=5.3.3",
            "composer/installers": "~1.0",
            "fuel/docs": "1.8.*",
            "fuel/core": "1.8.*",
            "fuel/auth": "1.8.*",
            "fuel/email": "1.8.*",
            "fuel/oil": "1.8.*",
            "fuel/orm": "1.8.*",
            "fuel/parser": "1.8.*",
            "fuelphp/upload": "2.*",
            "monolog/monolog": "1.18.*",
            "michelf/php-markdown": "1.4.*"
        },
    ...

    My composer.json now when session works:
    ...
        "require": {
            "php": ">=5.3.3",
            "composer/installers": "~1.0",
            "fuel/docs": "dev-1.9/develop",
            "fuel/core": "dev-1.9/develop",
            "fuel/auth": "dev-1.9/develop",
            "fuel/email": "dev-1.9/develop",
            "fuel/oil": "dev-1.9/develop",
            "fuel/orm": "dev-1.9/develop",
            "fuel/parser": "dev-1.9/develop",
            "fuelphp/upload": "2.*",
            "monolog/monolog": "1.18.*",
            "michelf/php-markdown": "1.4.*"
        },
    ...

    p.s. Thank you for warning about direct references to \Fuel\Core classes. I use direct references to \Fuel\Core classes instead aliased version because Eclipse doesn't autocomplete aliased version. I can't write code without autocompleting.
  • HarroHarro
    Accepted Answer
    If you need code completion, place https://gist.github.com/ryu-blacknd/3283072 in the root of your project (and in .gitignore).

    It's a few years old, so you might have to add one or two missing ones, but it fixes your problem.

    As to the session issue, with that composer json you should have 1.8.0.3 installed. If I look at the change list, I don't see any session fixes since then? https://github.com/fuel/core/compare/1.8.0.3...1.9/develop
  • File for code completion works fine.

    As you have written down: from 1.8.0.3 to 1.9/develop there are no changes which could affect sessions. I added every single change manually and session was not affected. But dev-1.9/develop version is OK for me.
  • Are you using native session emulation by any chance? Because there were some fixes there recently.

    We'll backport the 1.9/dev fixes to a new 1.8.0.x hotfix soon, so whatever this issue was, that would solve it.
  • I have native emulation setted on false currently. But if I set it on true it also won't work.

    I'll wait for new hotfix. After hotfix I'll notify if it works for me.
  • Ok, thanks. We'll post the release of the hostfix on Twitter and Facebook.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion