Index: functions/strings.php
===================================================================
--- functions/strings.php	(revision 13876)
+++ functions/strings.php	(working copy)
@@ -216,26 +216,40 @@
  * @return string the complete url for this page
  */
 function php_self () {
-    /*
-     * PHP 4.4.4 is giving the wrong REQUEST_URI. The Query string is missing.
-     * => I (stekkel) commented out the code because it's not realy needed. PHP_SELF in combinatiob
-     * with QUERY_STRING should do the job.
-     */
-//    if ( sqgetGlobalVar('REQUEST_URI', $req_uri, SQ_SERVER) && !empty($req_uri) ) {
-//      return $req_uri;
-//    }
 
-    if ( sqgetGlobalVar('PHP_SELF', $php_self, SQ_SERVER) && !empty($php_self) ) {
+    if (sqgetGlobalVar('PHP_SELF', $php_self, SQ_SERVER)
+     && !empty($php_self)) {
 
-      // need to add query string to end of PHP_SELF to match REQUEST_URI
-      //
-      if ( sqgetGlobalVar('QUERY_STRING', $query_string, SQ_SERVER) && !empty($query_string) ) {
-         $php_self .= '?' . $query_string;
-      }
+        // need to add query string to end of PHP_SELF to match REQUEST_URI
+        //
+        if (sqgetGlobalVar('QUERY_STRING', $query_string, SQ_SERVER)
+         && !empty($query_string)) {
+            $php_self .= '?' . $query_string;
+        }
 
-      return $php_self;
+        return $php_self;
     }
 
+    // some versions of PHP, perhaps specifically in use with lighttpd,
+    // return a blank string for PHP_SELF, so we use REQUEST_URI as a backup:
+    //
+    else if (sqgetGlobalVar('REQUEST_URI', $req_uri, SQ_SERVER)
+          && !empty($req_uri)) {
+
+        // some versions of PHP (such as 4.4.4) don't include the query
+        // string in REQUEST_URI, but most do... here's a fix for the
+        // odd ones out (assuming QUERY_STRING is reliable in those cases)
+        //
+        if (strpos($req_uri, '?') === FALSE
+         && sqgetGlobalVar('QUERY_STRING', $query_string, SQ_SERVER)
+         && !empty($query_string)) {
+
+            $req_uri .= '?' . $query_string;
+        }
+
+        return $req_uri;
+    }
+
     return '';
 }
 
