# Session not recognized globally

**URL:** <https://discourse.slimframework.com/t/session-not-recognized-globally/1854>\
**Category:** Questions\
**Created:** [October 2, 2017, 12:21pm UTC](https://discourse.slimframework.com/t/session-not-recognized-globally/1854 "2017-10-02T12:21:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![elshobokshy](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/elshobokshy/32/495_2.png) [@elshobokshy](https://discourse.slimframework.com/u/elshobokshy)\
**Post date:** [October 2, 2017, 12:21pm UTC](https://discourse.slimframework.com/t/session-not-recognized-globally/1854/1 "2017-10-02T12:21:18Z")

</div>

I have got a basic slim application with a `session_start()` in the index.php.

I gave $\_SESSION a value in a class called Validator.php :

```
class Validator
{
    
    protected $errors;

    public function validate($request, array $rules)
    {
        // filled $errors with data

        $_SESSION['errors'] = $this->errors;

        return $this;
    }

    public function failed() {
        return !empty($this->errors);
    }
}

```

In another class, I set that variable globally to work inside twig template :

```
class ValidationErrorsMiddleware extends Middleware
{
    
    protected $container;

    public function __invoke($request, $response, $next) {

        $twig = $this->container->view->getEnvironment();
        $twig->addGlobal('errors', $_SESSION['errors']);
        
        $response = $next($request, $response);
        return $response;
    }
}

```

And finally, calling the session variable in my Controller :

```
class AuthController extends Controller {

    public function getSignUp($request, $response)
    {
        // Render index view
    
    }

    public function postSignUp($request, $response)
    {
        $validation = $this->container->validator->validate($request, [
            'email' => v::email()->notEmpty(),
            'name' => v::notEmpty()->alpha(),
            'password' => v::NoWhitespace()->notEmpty(),         
        ]);
        var_dump($_SESSION); // no result
        var_dump($validation); //no result
        if($validation->failed()) {
            return $response->withRedirect($this->container->router->pathFor('auth.signup')); 
        }

        $user = User::create([
            'email' => $request->getParam('email'),
            'firstName' => $request->getParam('fname'),
            'lastName' => $request->getParam('lname'),
            'password' => password_hash($request->getParam('password'), PASSWORD_DEFAULT),
            'firstLogin' => '1',
        ]);

       return $response->withRedirect($this->container->router->pathFor('home')); 

    }

}

```

Inside my Controller, the $\_SESSION variable is always null, as if it didn’t have any values inside of it. A var\_dump of anything doesn’t work there. But there apparently IS values insinde the session variable as when I var dumb it in my index.php there are results showing up… I’m confused, what am I missing?

---

<div class="post-metadata">

**Author:** ![tstadler](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tstadler](https://discourse.slimframework.com/u/tstadler)\
**Post date:** [October 2, 2017, 5:42pm UTC](https://discourse.slimframework.com/t/session-not-recognized-globally/1854/2 "2017-10-02T17:42:59Z")

</div>

when do you start the session in your index.php?
