Changed check_login function to be able to use it without redirecting.