bryanjhv/slim-session

Session reset

FvsJ101 opened this issue · 4 comments

Hi, I have followed the instruction as in the read me file no session_* anything anywhere but in the middleware.

When I do a slim 4 redirect is seems to reset the session data. So nothing I set in my controllers outside of my middlewareis kept for the new view.
middlewaresetup
redirect
result

Please try adding Session middleware first.
I'll try to do a demo showing that redirects don't clear session unless another package (or own code) calls any session_* functions.

Can't reproduce it.

{
    "require": {
        "slim/slim": "^4.2",
        "bryanjhv/slim-session": "^4.0",
        "slim/psr7": "^0.5.0"
    }
}
require 'vendor/autoload.php';

use Slim\Factory\AppFactory;
use SlimSession\Helper as SessionHelper;
use Slim\Middleware\Session as SlimSession;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

$app = AppFactory::create();
$app->add(new SlimSession([
    'name' => 'example',
    'autorefresh' => true,
    'lifetime' => '30 minutes',
    'secure' => false,
    'httponly' => true,
]));

$app->get('/', function (Request $request, Response $response) {
    $helper = new SessionHelper();
    $helper->set('hello', 'world');

    $response->getBody()->write(json_encode($_SESSION));
    return $response
              ->withHeader('Content-Type', 'application/json')
              ->withStatus(200);
});

$app->get('/dest', function (Request $request, Response $response) {
    $response->getBody()->write(json_encode($_SESSION));
    return $response
              ->withHeader('Content-Type', 'application/json')
              ->withStatus(200);
});

$app->get('/redir', function (Request $request, Response $response) {
    return $response
              ->withHeader('Location', '/dest')
              ->withStatus(302);
});

$app->addErrorMiddleware(true, true, true);

$app->run();

Closing for lack of information and code to test.
Feel free to open a new issue adding that. Thanks.