public function requireBasicAuth($check_auth = '', $realm = 'Please enter your username and password')
    {

        $authorized = false;
        if (!isset($_SERVER['PHP_AUTH_USER'])) {
            header('WWW-Authenticate: Basic realm="' . $realm . '"');
            header('HTTP/1.0 401 Unauthorized');
            echo 'You must authenticate to continue';
        } else {

            if (is_callable($check_auth)) {
                $authorized = $check_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
            }

            if (!$authorized) {
                session_unset();
                unset($_SERVER['PHP_AUTH_USER']);
                return $this->requireBasicAuth($check_auth, $realm);
            }
        }

        return $authorized;
    }