move php check code before generated html code. token code moved between php and html