How can I use $_SESSION in form handler drupal 8?
The suberglobal $_SESSION still works in D8 and is used by core several times. 

For a correct Drupal 8 way see this change record. It shows how you access the session variable through the request object. But it doesn't show how to get the request object.

So this is an example for accessing the session in a form handler:

use Symfony\Component\HttpFoundation\Request;

  public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {

    $session = $request-&gt;getSession();
    $value = $session-&gt;get('mymodule_count', 0);
    $session-&gt;set('mymodule_count', $value + 1);
    $form['counter'] = ['#markup' =&gt; '&lt;p&gt;#' . $value . '&lt;/p&gt;'];


In a controller or form you can pull the request from the route parameter stack by putting a typed parameter Request $request in the build method.

If you are in a procedural form function get the request from \Drupal:

$request = \Drupal::request();