Try adding "print" statements after every statement. This is one way to see where in the script you are making it to. Then, if you see the WRONG print statement print you will know where to look. For example:
<?php
//If they are already loged in
if(is_logged_in()){
///////////////////////
print 'You are logged in';
loggedIn();
//Else if they have submited the form to login
} elseif(is_logging_in()){
///////////////////////
print 'You are logging in';
login($_POST['username'], $_POST['password']);
//Else this must be the first time they have come so show the login page
} else {
///////////////////////
print 'show the login form';
loginForm();
}
?>