The implementation of $_SERVER[‘SCRIPT_NAME’] and $_SERVER[‘PHP_SELF’] prior to 1.9.0 differs significantly from 1.9.0 and onward. The changes were made to be consistent with the Apache implementation generally expected by PHP applications.
The following examples demonstrate the difference.
<= 1.8.9 | >= 1.9.0 |
---|---|
app.yaml: - url: /.* script: index.php |
|
REQUEST_URI: / SCRIPT_FILENAME: /path/to/index.php SCRIPT_NAME: / PHP_SELF: / |
REQUEST_URI: / SCRIPT_FILENAME: /path/to/index.php SCRIPT_NAME: /index.php PHP_SELF: /index.php |
REQUEST_URI: /bar SCRIPT_FILENAME: /path/to/index.php SCRIPT_NAME: /bar PHP_SELF: /bar |
REQUEST_URI: /bar SCRIPT_FILENAME: /path/to/index.php SCRIPT_NAME: /index.php PHP_SELF: /index.php |
REQUEST_URI: /index.php/foo/bar SCRIPT_FILENAME: /path/to/index.php SCRIPT_NAME: /index.php/foo/bar PHP_SELF: /index.php/foo/bar |
REQUEST_URI: /index.php/foo/bar SCRIPT_FILENAME: /path/to/index.php SCRIPT_NAME: /index.php PHP_SELF: /index.php/foo/bar |
REQUEST_URI: /test.php/foo/bar SCRIPT_FILENAME: /path/to/index.php SCRIPT_NAME: /test.php/foo/bar PHP_SELF: /test.php/foo/bar |
REQUEST_URI: /test.php/foo/bar SCRIPT_FILENAME: /path/to/index.php SCRIPT_NAME: /index.php PHP_SELF: /index.php |
app.yaml: - url: /.* script: foo/index.php |
|
REQUEST_URI: /bar SCRIPT_FILENAME: /path/to/foo/index.php SCRIPT_NAME: /bar PHP_SELF: /bar |
REQUEST_URI: /bar SCRIPT_FILENAME: /path/to/foo/index.php SCRIPT_NAME: /foo/index.php PHP_SELF: /foo/index.php |
Note the odd behavior of PHP_SELF which is consistent with PHP on Apache.
Many frameworks and applications depend on SCRIPT_NAME to determine if the application is running within a subdirectory, typically within an Apache virtual host, and as such will not be affected by this change. On the other hand this may break custom applications or frameworks that have been configured to work with the previous implementation.