How do I access $_SESSION in a view?
In case this might be helpful for other (beginners): Using the session object in a custom controller class with dependency injection.

Drupal\user\PrivateTempStoreFactory;

class mymodule_Controller extends ControllerBase {

  /**
  * The user's private $tempStore object.
  *
  * @var \Drupal\user\PrivateTempStoreFactory
  */
  protected $tempStore;

  public function __construct(PrivateTempStoreFactory $temp_store_factory) {
    $this-&gt;tempStore = $temp_store_factory-&gt;get('mymodule_name');
  }

 /**
 * {@inheritdoc}
 */
 public static function create(ContainerInterface $container) {
   return new static(
     $container-&gt;get('user.private_tempstore')
   );
 }

 // Now get and set values in tempstore
 public function foo() {
  $foo = "xyz";
  // Set a session object "bar" and give it value $foo
  $this-&gt;tempStore-&gt;set('bar', $foo);

  // Get the 'bar' object from the session object.
  $value = $this-&gt;tempStore-&gt;get('bar');
 }

}