Where are my sessions in Slim PHP framework?

10,479

Slim has relied on encrypted HTTP cookies to persist session data; if you do not have cookies, you won't have sessions unless you set the session handler to null as you have done above.

Version 1.6.0 (currently in the develop branch) does not make any assumptions about sessions; instead, version 1.6.0 requires that you configure and start your own session (if using PHP's native session handling). Version 1.6.0 also abstracts the legacy session handling into middleware so that you can continue using encrypted cookies to persist session data if that's what you prefer.

If you have any further questions, I encourage you to post them to the official Slim Framework support forum at http://help.slimframework.com/.

Best, Josh

Share:
10,479
naivedeveloper
Author by

naivedeveloper

Updated on June 24, 2022

Comments

  • naivedeveloper
    naivedeveloper almost 2 years

    I'm using version 1.5.0 of the Slim PHP framework, and I'm having problems with sessions. I've had no problems in the past (using Slim), so it leads me to believe it's either something changing with Slim, or something with my setup. Here is a basic snippet of routes in my index.php page.

    $app->get('/test', function() use($app) {
        $_SESSION['test'] = 'blah';
        var_dump($_SESSION);
    });
    
    $app->get('/test2', function() use ($app) {
        var_dump($_SESSION);
    });
    

    The '/test' route outputs:

    array(1) { ["test"]=> string(4) "blah" }
    

    The '/test2' route outputs:

    array(0) { }
    

    What is up with my sessions. Am I doing something wrong? Should I be using something else than PHP's native sessions? I've even tried initializing Slim with the following property:

    $app = new Slim(array(
        'session.handler' => null
    ));
    

    Both options, to no avail.