It could be a problem with the session_save_path in your php.ini file and sessions might just be not working. Is there anything else that might be taking it to the index page? Are you sure the session variables aren't being saved.
I'd probably debug by setting a session variable in php on one page and see if I can access it on another page. If the site doesn't store sessions properly then the code on the pages isn't the problem.
If sessions work, then I'd consider if it is somehow going to the index page without running the login code. Maybe the form action is set wrong?