Session.php
private function verifySocket($ip)
    {
        if ($ip) {
            $_SERVER['REMOTE_ADDR'] = $ip;
        }

        preg_match ('#PHPSESSID=([^;\s]+)#', $_SERVER['HTTP_COOKIE'] ?? false, $array, PREG_OFFSET_CAPTURE);

        $session_id = $array[1][0] ?? false;

        if (!$session_id) {
            print 'Failed to capture PHPSESSID' . PHP_EOL;
            die(1);
        }

        $db = Database::database();
        $sql = 'SELECT count(*) FROM sessions WHERE user_ip = ? AND session_id = ? LIMIT 1';
        $stmt = $db->prepare($sql);
        $stmt->execute([$_SERVER['REMOTE_ADDR'], $session_id]);
        $session = $stmt->fetchColumn();
        self::$session_id = $session_id;
        if (!$session) {
            if (SOCKET) {
                print 'BAD ADDRESS :: ' . $_SERVER['REMOTE_ADDR'] . "\n\n";
            }
            die(0);
        }
        session_id($session_id);
    }
private function verifySocket($ip)
    {
        if ($ip) {
            $_SERVER['REMOTE_ADDR'] = $ip;
        }

        preg_match ('#PHPSESSID=([^;\s]+)#', $_SERVER['HTTP_COOKIE'] ?? false, $array, PREG_OFFSET_CAPTURE);

        $session_id = $array[1][0] ?? false;

        if (!$session_id) {
            print 'Failed to capture PHPSESSID' . PHP_EOL;
            die(1);
        }

        $db = Database::database();
        $sql = 'SELECT count(*) FROM sessions WHERE user_ip = ? AND session_id = ? LIMIT 1';
        $stmt = $db->prepare($sql);
        $stmt->execute([$_SERVER['REMOTE_ADDR'], $session_id]);
        $session = $stmt->fetchColumn();
        self::$session_id = $session_id;
        if (!$session) {
            if (SOCKET) {
                print 'BAD ADDRESS :: ' . $_SERVER['REMOTE_ADDR'] . "\n\n";
            }
            die(0);
        }
        session_id($session_id);
    }
This function was created to make sure all socket request come from
an existing user who has a session stored in our database. If database
session storage is turned off this method will fail and exit.

@param $ip - the ip address to look up from our database.