in reply to Debugging hell!!

You could check to make sure $cookies{'user'} and $cookies{'pass'} are defined and if they aren't, do what you need to do (probably call loginpage and exit since no cookies means they're not logged in, right?).