Are you including an html file with the template?
If so, that could throw it off because you can't release the html header before the header() function in PHP. You should do your PHP at the very top of the page before all those includes (unless it's your database connection one).
I'm assuming logincheck is with the variable you need? You can do that before. But you should always release your html header after using header() functions in php.