From:             ceefour at gauldong dot net
Operating system: Apache/1.3.33 (Unix) mod_ssl/2.8
PHP version:      4.3.10
PHP Bug Type:     CGI related
Bug description:  PHP_SELF incorrect in CGI mode (same as PATH_INFO), very old 
bug still existing

Description:
------------
First of all, let me say this is a very old bug (over two years old).
There are references all over the net for this, but here's what I found
inside PHP's bug report:

http://bugs.php.net/bug.php?id=14307
http://bugs.php.net/bug.php?id=18942
http://bugs.php.net/bug.php?id=8252

The most related bug (actually this exact bug) is Bug #18942: $PHP_SELF is
set to HTTP_SERVER_VARS[PATH_INFO] if available.

The response (which I think is pure bogus) is:
-------------
This bug has been fixed in CVS.
...
It's fixed in cvs as of today.
-------------
well, that "today" is somehow over two years ago. ;-)

Anyway, the problem is simple. Considering this script:

http://www.gauldong.net/phpinfo.php/test

In other than CGI mode, PHP_SELF will be "/phpinfo.php/test", which is
correct. But in CGI mode, PHP_SELF will be "/test", which is incorrect.
Since it does not refer to the URI of the current script, but rather the
PATH_INFO.

You can test it for yourself. The above URL I provided as an example is
real, it's not just there for an example. So try it. You can scroll down
to the the middle of the page to find out the value of PHP_SELF, but an
easier and quicker way is just to look whether the PHP/Zend images load.
Well, they don't, since they use PHP_SELF which has an incorrect value.

My workaround for this bug is as follows (not how handling this special
quirk is *SOOOO* unnecessary):

        /**
         * Returns URI of currently executing PHP script.
         *
         * I noticed some weirdness in PHP behaviour (maybe related to operating
system and/or Apache version/platform).
         * In my WinXP box PHP_SELF works fine. But in Linux production server
PHP_SELF is the same as PATH_INFO
         * and SCRIPT_URL seems to contain the real correct PHP_SELF. However,
SCRIPT_URL does not exist in my WinXP box.
         * So I guess the the only thing that is common in two servers is the
REQUEST_URI server variable. So I parse
         * this using parse_url() and returns the path portion.
         * 
         * @access public
         * @static This method can be called statically.
         * @see GetServer()
         * @return string PHP script URI.
         */
        /*public static*/ function GetSelf() {
                if (!Types::IsEmpty($_SERVER['SCRIPT_URL'])) {
                        return $_SERVER['SCRIPT_URL'];
                } else {
                        $uri = $_SERVER['REQUEST_URI'];
                        $parsed = @parse_url($uri);
                        if (isset($parsed)) return $parsed['path'];
                        else return $_SERVER['PHP_SELF'];
                }
        }


Reproduce code:
---------------
echo $_SERVER['PHP_SELF'];

Expected result:
----------------
/phpinfo.php/test

Actual result:
--------------
/test

-- 
Edit bug report at http://bugs.php.net/?id=31843&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=31843&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=31843&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=31843&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=31843&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=31843&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=31843&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=31843&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=31843&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=31843&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=31843&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=31843&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=31843&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=31843&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=31843&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=31843&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=31843&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=31843&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=31843&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=31843&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=31843&r=mysqlcfg

Reply via email to