Forum Moderators: coopster
I've noticed that the _SERVER["PHP_SELF"] variable acts strangely under these conditions.
In this example, test is an extensionless php file with phpinfo() in it. If I call 'test', I get:
_SERVER["DOCUMENT_URI"]/test
_SERVER["SCRIPT_FILENAME"] /usr/local/apache/htdocs/test
_SERVER["PATH_INFO"]no value
_SERVER["PHP_SELF"] is blank
If I call test/1, I get:
_SERVER["DOCUMENT_URI"]/test/1
_SERVER["SCRIPT_FILENAME"] /usr/local/apache/htdocs/test
_SERVER["PATH_INFO"]/1
_SERVER["PHP_SELF"]/1
Is this typical behaviour under fastcgi? Why would _SERVER["PHP_SELF"] be blank in the first instance and equal to the path_info in the second.
Thanks.
_SERVER["DOCUMENT_URI"]/test
_SERVER["DOCUMENT_URI"]/test/1
So if the file test does not exist then as PHP_SELF is "The filename of the currently executing script, relative to the document root" this would be blank as there is no file. Im not sure what happens when you call a directory, not a file. I would guess that as there would be no "executing script" that the value would be blank, however that is untested.
Or another option is -
Do you have any rewriting going on? As in both of your examples the _SERVER["SCRIPT_FILENAME"] is the same. So are you actually calling test?1 (or something like that) when you are calling test/1?
As if you are rewriting then there may be an issue with the rewrites, and not php. So get rid of the rewrites and see if that sorts your problem.
As a side you may want to have a look at the Predefined Variables [php.net] section in the manual. As the only place you will find PATH_INFO is under the PATH_TRANSLATED section. So you may want to consider using another of the variables. As some of the variables will only be available on some servers.
In both cases, test is an extensionless PHP file. In Apache it's run under the Files directive. It's for a clean url.
<Files test>
ForceType application/x-httpd-php
</Files>
In Apache, the results are:
/test : _SERVER["PHP_SELF"]/test
/test/1 : _SERVER["PHP_SELF"]/test/1
Under fastcgi/nginx:
/test : _SERVER["PHP_SELF"]no value
/test/1 : _SERVER["PHP_SELF"]/1
So it's as I expected in Apache but not under fastcgi.