Question: I have created a session variable in one controller and I want to access it in another controller. In `loginsuccess` controller I set the session: 

```
$session->set('id',$id);

```

How can I access this variable in another controller?

Answer: 
There is `session` service which you should use:

```
$id = $this->get('session')->get('id');

```

or

```
$this->get('session')->set('id', $id);

```
While Cyprian answer is valid, you will find in the documentation the following usage:

```
use Symfony\Component\HttpFoundation\Session\Session;

$session = new Session();
$session->start();

// set and get session attributes
$session->set('id',$id);
$session->get('id'); //this is the line you are looking for

```

<http://symfony.com/doc/master/components/http_foundation/sessions.html>

Note:

> 
> While it is recommended to explicitly start a session, a sessions will
>  actually start on demand, that is, if any session request is made to
>  read/write session data.
> 
> 
>