ensure_session() cannot always create a session.
Add $Opt["redirectToHttps"].
Less jankass error message