Monday, June 15, 2009

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.

And here is the rest of it.

1 comment:

Best for u said...

mmm, good,
i like your blog,
don't forget me, have good thing to tell you