Login doesn't "stick" after upgrade to PHP 5.2+
This is a specific problem that affects older versions of Drupal on a server running PHP 5.2 or later. Often it arises when PHP is upgraded (sometimes without your knowing!).
Symptom: You can appear to log in OK, but on the very next page view the system seems to forget that you have just logged in and you revert to being an "anonymous" user.
If you are running Drupal 5.x or later then this specific problem won't affect you, so if you still have trouble staying logged in then check here.
This problem occurs due to the way PHP 5.2+ handles objects in session handlers. It affects all Drupal versions up to Drupal 4.6.10, Drupal 4.7.4 and Drupal 5-beta 1 inclusive.
The best method of fixing this is to upgrade to the latest official release of a supported version of Drupal. Currently (Dec 2008) this means the latest release of either the 5.x or the 6.x series.
For those wishing not to do a full upgrade yet but who need an "instant fix", you can add the following line at the bottom of your settings.php file:
// Temporary fix to login/sessions problem.
// Remove this line when upgrading to 4.6.11, 4.7.11 or 5.x or later.
register_shutdown_function('session_write_close');You should regard this as a temporary fix only. If you subsequently upgrade your site to a newer version of Drupal you should remove this line from settings.php to prevent potential incompatibility with future versions of Drupal.
The problem is fixed in the 4.6.11 and 4.7.5 releases of Drupal. So another option for 4.6.x and 4.7.x users is to upgrade to the final release of the 4.6.x/4.7.x series - 4.6.11 or 4.7.11, which are available here.
Note that while Drupal 5.0 doesn't exhibit this particular problem with PHP 5.2 it is still not fully compatible with this version of PHP; Drupal 5.1 is fully compatible (but of course doesn't contain the security fixes in the latest 5.x release).
Here is the original issue in which this problem was identifed and fixed.

Why am i experiencing this on D6.8?
Hi,
My users are constantly logged out and have to re-login. I am Drupal 6.8 the latest release. I am on MYSQL 5.0.67.
Thanks in advance,
H
Fix does not work for 6.8 and 5.14-DE
Server: Debian etch
MySQL: 5.0.32
PHP: 5.2.0
None of the other fixes that can be found on the net work either...
>None of the other fixes
>None of the other fixes that can be found on the net work either
The specific problem described on this page does not occur in 6.8 or 5.14. You are probably experiencing something similar but fundamentally different, and possibly server-related. First place to look would be cookie handling in PHP. Occasionally an incorrectly configured cache between the user and the server is implicated. Suggest you open a new forum topic.
gpk
----
www.alexoria.co.uk
I'm dealing wit the same
I'm dealing wit the same issue, only a little different in action. After installation I am logged in to the system and I can apply changes which are visible while logged in. However, after I logout and try to view the pages as an outsider viewing the web site, I get the "Access denied" error. To be clear, I just want to backout and view the web site as if I was a visitor looking from the outside in and just check out the pages to see how they look and if the look right, instead, I get "Access Denied" and I can't view anything until I log back in as admin. My drupal version is 6.6, My PHP version is 5.2.6 and my SQL version is 5.0.41, although there is also present a SQLiteManager whichsays its version 2.8.17 - 3.3.17. Thxs.
D-
Does the "anonymous" user
Does the "anonymous" user have "access content" permission? If this doesn't help then I suggest opening a new forum topic.
gpk
----
www.alexoria.co.uk
Thanks!
Thanks!, That did the trick!. You guys are the greatest!
Thanks for posting this
Thanks for posting this explanation and fix. It was a big help.
Login doesn't "stick", PHP5.2+
It helps me too.
Thanks you very much for this guide.
ChanHan Hy