Fix token upgrade error

If a user is already logged in and visits a page, then it may create a
token using the json encoding.  Then user goes to upgrade the php
unserialize() fails.  Now we check in case of php unserialize()
failure that the token isn't a valid json token before erroring out.

Fixes #17806
Go to install after login if db upgrade required

If admin checks are enabled and database upgrade is required then
redirect to install page instead of the return or default pages.
This will help direct the user towards upgrading rather than
visiting normal pages and getting php errors.

Fixes #17806
Merge pull request #532 from vboctor/Issue17806_UpgradeError

Fixes #17806: Upgrade your installation consistently failing

The admin checks were mostly moved as is to the top of the page to use them to set a hidden field on the form. However, the warnings are displayed at the same location as before.