To add the condition for the session ID when the user is logged out, you can modify your code as follows:
<?php
// displaying errors faced
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// call the database file
include('includes/db.inc.php')...