PHP 5.2.4 and .5 break phpBB3rc7 on Windows

From RavenWiki
Jump to navigationJump to search

The problem

An incompatible change in PHP 5.2.4 and 5.2.5 (apparently affecting only systems running Windows) breaks various standard phpBB3rc7 (and earlier) functionality, unrelated to which authentication is used. Additionally, it breaks the modifications for Raven authentication. The specific problem seen is that initial login still worked but re-authentication for Admin Control Panel access failed. Typical symptoms are a redirection or link to an incorrect URL, with the top-level directory component missing from the URL path (e.g. for a phpBB3 installation accessed with URLs starting /phpBB3/ , "phpBB3/" would be missing), resulting in a "404 Not Found" error.

The cause of the problem is that in the affected PHP versions, the behaviour of the realpath() function changed incompatibly and includes a trailing "/" at the end of the directory paths that it returns. While that might appear "mostly harmless", it actually breaks some of the path manipulation and comparison in phpBB which relied on the prior behaviour. It also breaks other PHP applications that get caught out by the change.

After initially denying that it was a bug (PHP bug #42778]) it was accepted as an incompatible change that needed to be fixed (PHP bug #43248), so future releases should be fixed - but that leaves PHP 4.2.4 and 4.2.5 affected by the problem.

The phpBB3 developers are now aware of that problem and a solution (to remove any extraneous trailing "/"s from the result of realpath()) will be included in future versions, but phpBB3rc7 and earlier will remain affected by the problem.

The solution

NB Making this change is pointless unless you are using phpBB3rc7 (with or without the modifications for Raven authentication) on a system that is affected by the problem (or will be affected after a planned PHP upgrade).

Save a copy of the existing installed includes/functions.php file and then use a text editor (Notepad or Wordpad should be fine) make the change described below. If correctly applied, it should resolve the problems (for phpBB3rc7 in general and Raven authentication in particular).

The functions.php file includes two definitions of the function phpbb_realpath(), one which is used in configurations where PHP does not provide a realpath() function. When PHP provides a realpath(), an alternative version of phpbb_realpath() is used, and it's the latter which needs to be changed.

Search for a line

        function phpbb_realpath($path)

around line 545 of the file, and then search again for the second definition of the function, at around line 696.

The version of phpbb_realpath you're looking for should be very basic, just calling PHP's realpath() function:

        /**
        * A wrapper for realpath
        * @ignore
        */
        function phpbb_realpath($path)
        {
                return realpath($path);
        }

You need to change that (without changing any other lines lines) to:

        /**
        * A wrapper for realpath
        * @ignore
        */
        function phpbb_realpath($path)
        {
                $path = realpath($path);

                // Check for DIRECTORY_SEPARATOR at the end (and remove it!)
                if (substr($path, -1) == DIRECTORY_SEPARATOR)
                {
                        return substr($path, 0, -1);
                }

                return $path;
        }

Save the changed file, and try phpBB3 again. If the change has been applied correctly, it should now work. If not, try reinstating the initial version of the file (from the saved copy) and try the edits again, being careful not to change anything (or allow the editor to change anything, e.g. by wrapping long lines!) other than the lines that need to be changed.