# Session is not persistent

**URL:** <https://discourse.slimframework.com/t/session-is-not-persistent/2516>\
**Category:** Questions\
**Created:** [July 7, 2018, 8:03am UTC](https://discourse.slimframework.com/t/session-is-not-persistent/2516 "2018-07-07T08:03:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fillibuster](https://avatars.discourse-cdn.com/v4/letter/f/7ba0ec/32.png) [@fillibuster](https://discourse.slimframework.com/u/fillibuster)\
**Post date:** [July 7, 2018, 8:03am UTC](https://discourse.slimframework.com/t/session-is-not-persistent/2516/1 "2018-07-07T08:03:43Z")

</div>

Hi,

I try to use a session with slim (bryanjhv/slim-session), but after a redirect the session value does not exist. What is wrong here?:

```
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
use \Interop\Container\ContainerInterface as ContainerInterface;

class AppController extends FilterController
{
protected $ci;
protected $user_session;

//Constructor
public function __construct(ContainerInterface $ci)
{
    $this->ci = $ci;
    $this->user_session = new \SlimSession\Helper;
} 

public function login($request, $response, $args)
{
    $data = $request->getParsedBody();
    $user = ORM::for_table('users')->where('email', $data['email'])->find_one();
    if ($user !== false){
        $this->user_session->set('user_id', $user->id);
        //Printing this works!
        //echo $this->user_session->user_id;
        return $response->withRedirect('/app/list');
    }
}

public function list($request, $response, $args)
{
    //This don't work :-(
    echo $this->user_session->user_id;
}

...

```

Thank you so much

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [July 7, 2018, 12:11pm UTC](https://discourse.slimframework.com/t/session-is-not-persistent/2516/2 "2018-07-07T12:11:57Z")

</div>

Hi @fillibuster

Have you already added the middleware according to the [documentation](https://github.com/bryanjhv/slim-session)?

```php
$app->add(new \Slim\Middleware\Session([
  'name' => 'dummy_session',
  'autorefresh' => true,
  'lifetime' => '1 hour'
]));

```
