From: pdontthink Date: Thu, 21 Jan 2010 14:40:52 +0000 (+0000) Subject: Make php_self() more robust. Seems to fix certain lighttpd issues, such as probably... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=39790db7cdf3a4705e169e4f57450449ae23b570;p=squirrelmail.git Make php_self() more robust. Seems to fix certain lighttpd issues, such as probably #1741469 git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@13886 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/functions/global.php b/functions/global.php index 5c9f497f..ebcfb98d 100644 --- a/functions/global.php +++ b/functions/global.php @@ -678,21 +678,38 @@ if (!function_exists('session_regenerate_id')) { * @since 1.2.3 */ function php_self () { - // PHP 4.4.4 apparently gives the wrong value here - missing the query string - // this code is commented out in the 1.4.x code, so we'll do the same here - //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 '';