There's a problem with using the $_SERVER['DOCUMENT_ROOT'] variable, because it's often not correctly set. While serendipity does a lot of work to determine where and how it's installed, I still get some warnings because the document root isn't a real place.
I found a solution to this problem on http://www.helicron.net/php/, but on my host, the basename/realpath trick doesn't do it, and I have to get the $absolutepath from SCRIPT_FILENAME. Otherwise, it looks perfect, I just have to set the $_SERVER['DOCUMENT_ROOT'] variable to the calculated value.