You need to start your page with a session, it cannot be used elsewhere in your code, it must also be on all of your pages where you make a reference to '$_SESSION'.
At the top of your page BEFORE any code, add the following -
if (session_status() == PHP_SESSION_NONE) {
session_start();
}