#21261 [Com]: $_SERVER['PHP_SELF'] gives wrong info

From: Date: Thu, 17 Apr 2003 12:38:08 +0000
Subject: #21261 [Com]: $_SERVER['PHP_SELF'] gives wrong info
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-37808@lists.php.net to get a copy of this message
ID: 21261 Comment by: adamski at echtzeit dot com Reported By: undream at yifan dot net Status: Closed Bug Type: Scripting Engine problem Operating System: linux 2.4.18 - slack 8.1 PHP Version: 4.3.0 Assigned To: shane New Comment: I just tried PHP 4.3.1 as cgi on SUSE 6.4/Apache 1.3.19 and the bug is still there. The workaround helps though :) Previous Comments: ------------------------------------------------------------------------ [2003-02-07 16:25:42] russ at iris dot washington dot edu Tilde expansion in URL has same problem on Solaris. I was able to use the provided workaround: $_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); } to fix the same problem (invalid PHP_SELF) on Solaris 2.7 Sparc, PHP 4.3.0 (fresh). Simply doing phpinfo(); and then appending the value of PHP_SELF onto an 'ls ' statement yielded "no such file". The file did not exist: $ ls /~russ/tryseed/showSeed.phtml /~russ/tryseed/showSeed.phtml: No such file or directory What I can contribute here is this: I was running out of a "pubic_html" subdirectory off of ~russ (above), and the URL typed into IE 5.2 (Mac OS X) was: "http://hostname/~russ/tryseed/showSeed.html" --Thank you to whoever came up with that workaround above. ------------------------------------------------------------------------ [2003-01-25 16:06:27] shane@php.net This bug has been fixed in CVS. In case this was a PHP problem, snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. In case this was a documentation problem, the fix will show up soon at http://www.php.net/manual/. In case this was a PHP.net website problem, the change will show up on the PHP.net site and on the mirror sites in short time. Thank you for the report, and for helping us make PHP better. This is now fixed in cvs: 4.3: http://cvs.php.net/co.php/php4/sapi/cgi/cgi_main.c?r=1.190.2.12 5.0: http://cvs.php.net/co.php/php4/sapi/cgi/cgi_main.c?r=1.208 ------------------------------------------------------------------------ [2003-01-17 06:36:29] tapken at engter dot de 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------------------------------------ ------------------------------------------------------------------------ [2003-01-13 11:41:12] daniel dot gorski at develnet dot 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 at engter dot 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. ------------------------------------------------------------------------ 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

« previous php.bugs (#37808) next »