#21261 [Com]: $_SERVER['PHP_SELF'] gives wrong info
| From: | tapken at engter dot de | Date: | Fri, 17 Jan 2003 12:36:29 +0000 |
| Subject: | #21261 [Com]: $_SERVER['PHP_SELF'] gives wrong info | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-30345@lists.php.net to get a copy of this message | ||
ID: 21261
Comment by: tapken@engter.de
Reported By: undream@yifan.net
Status: Open
Bug Type: Scripting Engine problem
Operating System: linux 2.4.18 - slack 8.1
PHP Version: 4.3.0
Assigned To: shane
New Comment:
Sorry, my PHP-Based Workaround seems to be buggy in some cases, too...
Here is a quick & dirty bugfix for the quick & dirty workaround :-)
Btw, it would be nice if the bug is fixed in PHP 4.3.1...
-snip----------------------------------------
// Small Workaround for a bug in PHP 4.3.0/cgi
// See http://bugs.php.net/bug.php?id=21261 for
details
$_SERVER['SCRIPT_NAME'] = substr($_SERVER['PATH_TRANSLATED'],
strlen($_SERVER['DOCUMENT_ROOT']));
if (substr($_SERVER['SCRIPT_NAME'], 0, 2) == '//') {
$_SERVER['SCRIPT_NAME'] = substr($_SERVER['SCRIPT_NAME'], 1);
}
$PHP_SELF =
$SCRIPT_NAME =
$_SERVER['PHP_SELF'] =
$_SERVER['SCRIPT_NAME'];
-snip------------------------------------
Previous Comments:
------------------------------------------------------------------------
[2003-01-13 11:41:12] daniel.gorski@develnet.org
That (or similar) urgent problem occurs here too. PHP versions before
mid december were not affected IMO.
At first today I've checked out the "php4" and "php5" modules from CVS,
configured, and build them. After installation of the CGI binaries I
detected a problem with $_SERVER['PHP_SELF']:
a) the PHP4 version shows "no value"
b) the PHP5 version shows illegal characters, cut off strings with low
ASCII values etc. Depending on the namebased vhost name the value of
PHP_SELF looks like "ind##" instead of "index.php" ("#" should
represent low ASCII chars, which are shown as boxes here) of just "5"
which is definitely the last char of "index.php5". Short: looks like a
pointer on a string array is bent somewhere.
The problem insist with and without '--enable-force-cgi-redirect' in
both versions. As an example you may want to take a look at
http://daniel-gorski.de/index.php4 (PHP4 CGI)
http://daniel-gorski.de/index.php5 (PHP5 CGI)
and compare the values of $_SERVER['PHP_SELF']. Additionally the PHP5
version has a strange "Zend Extension" date: 90021012. OTOH this value
seems to be correct in the PHP4 version.
The operating system is Linux (RedHat 6.2).
I would appreciate to see this bug solved as soon as possible, because
this is a dramatic show stopper for a few ZE2 applications I am
developing & running.
What required information can I provide to help to solve this problem?
regards dtg
------------------------------------------------------------------------
[2003-01-09 14:57:05] tapken@engter.de
Quick & Dirty PHP-Based workaround:
Put this code in a file and add it to auto_prepend_file-directive in
php.ini:
-snip----------------------------------------
// Small Workaround for a bug in PHP 4.3.0/cgi
// See http://bugs.php.net/bug.php?id=21261 for
details
$_SERVER['SCRIPT_NAME'] = substr($_SERVER['PATH_TRANSLATED'],
strlen($_SERVER['DOCUMENT_ROOT']));
$PHP_SELF =
$SCRIPT_NAME =
$_SERVER['PHP_SELF'] =
$_SERVER['SCRIPT_NAME'];
-snip------------------------------------
Works fine for me... If PHP is used as CLI it may be neccessary to
check current mode before running this code.
------------------------------------------------------------------------
[2003-01-07 13:30:23] tapken@engter.de
There is no space in SCRIPT_NAME on my localhost, this was an
copy&paste-error. But the "I" at the end exists.
------------------------------------------------------------------------
[2003-01-07 13:27:55] tapken@engter.de
Same for me, your patch seems to have no affect.
I checked the debugging output from cgiwrap which says:
[...]
Fixing Environment Variables.
Environment Variables:
QUERY_STRING: ''
SCRIPT_NAME: '/phpinfo.php'
SCRIPT_FILENAME: '<DOCUMENT_ROOT>/phpinfo.php'
REDIRECT_URL: '<NULL>'
PATH_INFO: '/phpinfo.php'
PATH_TRANSLATED: '<DOCUMENT_ROOT>/phpinfo.php'
REMOTE_USER: '<NULL>'
REMOTE_HOST: '<NULL>'
REMOTE_ADDR: '217.4.137.70'
[...]
Seems to be ok?! But PHP_SELF has no value.
On my localhost PHP 4.3/CGI works with cgiwrap. The same paragraph with
this machine:
[...]
Fixing Environment Variables.
Environment Variables:
QUERY_STRING: ''
SCRIPT_NAME: '/php/ phpinfo.phpI'
SCRIPT_FILENAME: '<DOCUMENT_ROOT>/php/phpinfo.php'
REDIRECT_URL: ''
PATH_INFO: '/php/phpinfo.php'
PATH_TRANSLATED: '<DOCUMENT_ROOT>/php/phpinfo.php'
REMOTE_USER: ''
REMOTE_HOST: ''
REMOTE_ADDR: '192.168.23.2'
[...]
In this case, script_name is broken for some reason (don't ask me why,
i didn't find out). But PHP_SELF has the correct value! On both server
SCRIPT_NAME isn't listed in the phpinfo()-Output.
Hope this will help.
------------------------------------------------------------------------
[2003-01-07 00:42:23] shane@php.net
undream@yifan.net: email me your httpd.conf, php.ini and the test
script you use. You can remove anything from the files that are
private. Also, as per spec PATH_TRANSLATED will be empty unless you
have PATH_INFO, which is path data *after* the script in a url:
http://host/script.php/path/info?query-string
The only thing I'm concerned about is the garbled PHP_SELF. PHP_SELF
is the same as SCRIPT_NAME, is SCRIPT_NAME also garbled?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/21261
--
Edit this bug report at http://bugs.php.net/?id=21261&edit=1