With php 5.2.0 the userid of every session will be set to uid 0. This occurs because the global user object is not available in the sess_write() session handler.
So you can successfully login however at the next page you will be uid 0 aigain.
I've found this in the php docs to session_set_save_handler():
Write and Close handlers are called after destructing objects since PHP 5.0.5. Thus destructors can use sessions but session handler can't use objects. In prior versions, they were called in the opposite order. It is possible to call session_write_close() from the destructor to solve this chicken and egg problem.
However with php 5.1.x everything was fine. Probably the new memory manager in php5.2.0 changed things.
I tried adding a call to session_write_close() and it really solved all problems :)
The mysqli db layer seems to already addresss this issue for itself (line 87)
Note: This bug affects every drupal version.