Forum Moderators: coopster

Message Too Old, No Replies

Is there a problem with SERVER["PHP SELF"] under fastcgi?

         

ianevans

1:00 am on Mar 16, 2008 (gmt 0)

10+ Year Member



I'm running php 5.3.5 through fastcgi under ngix.

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.

Habtom

12:12 pm on Mar 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not directly related to your question, but

_SERVER["PHP_SELF"] OR $_SERVER["PHP_SELF"]?

Maybe there is some explanation to that?

PHP_Chimp

3:13 pm on Mar 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



_SERVER["DOCUMENT_URI"]/test
_SERVER["DOCUMENT_URI"]/test/1

So is /test actually /test/, as in a directory? As it would appear that way when you have /test/1. Or do you have both test (file) and test (directory) / 1 (file) set up?

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.

ianevans

1:00 am on Mar 17, 2008 (gmt 0)

10+ Year Member



PHP Chimp,

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.