From:
Operating system: Gentoo Linux (2.6.39-gentoo-r3)
PHP version: 5.3.6
Package: FPM related
Bug Type: Bug
Bug description:setting correct SCRIPT_NAME vs PHP_SELF is impossible in
certain circumstances
Description:
------------
I am running nginx 1.0.4 with php-fpm and php 5.3.6.
It seems that PHP_SELF has strong dependency on the setting of SCRIPT_NAME.
When setting SCRIPT_NAME to something, $_SERVER['PHP_SELF'] will contain
PHP_SELF environment value concatenated with environment value of
SCRIPT_NAME.
If SCRIPT_NAME is not set to anything, then $_SERVER['PHP_SELF'] contains
what
is passed to the environment, however, since SCRIPT_NAME is not set, PHP
scripts
that rely on SCRIPT_NAME will not work.
Example #1:
accessing URL: /index.php/some/url
setting server variables:
SCRIPT_NAME /some/url
PHP_SELF /some/url
result:
print $_SERVER['SCRIPT_NAME']; // outputs: "/some/url" - OK
print $_SERVER['PHP_SELF']; // outputs: "/some/url//some/url" - NOT OK!
Example #2:
SCRIPT_NAME (unset)
PHP_SELF /some/url
result:
print $_SERVER['SCRIPT_NAME']; // outputs: ""
print $_SERVER['PHP_SELF']; // outputs: "/some/url"
Example #3:
SCRIPT_NAME /some/url
PHP_SELF (unset)
result:
print $_SERVER['SCRIPT_NAME']; // outputs: "/some/url"
print $_SERVER['PHP_SELF']; // outputs: ""
---
Bottom line: if configured as demonstrated in the first example, scripts
that
rely on SCRIPT_NAME will work properly, but scripts that require PHP_SELF
won't
work, as it contains the invalid URL; if configured as shown in the second
example, scripts that rely on PHP_SELF work properly, but scripts that
require
SCRIPT_NAME, don't work at all; lastly, if configured as in the third
example,
scripts that use SCRIPT_NAME will work properly, but scripts that use
PHP_SELF
won't work, as PHP_SELF is empty.
Any workaround for this issue?
When using mod_php with apache, both SCRIPT_NAME and PHP_SELF can be set to
the
same value, and will be interpreted by PHP exactly like they are passed.
However, in FCGI/PHP-FPM environment I cannot find a way to set them both
to the
same value!
How is $_SERVER['PHP_SELF'] being constructed?
Why should it rely on SCRIPT_NAME at all?
How to set server environment correctly, so it is the same under FastCGI
and
under mod_php / apache 2.2?
Andrejs
Test script:
---------------
<?php
print '<pre>';
printf("SCRIPT_NAME: \"%s\"\n", $_SERVER['SCRIPT_NAME']);
printf("PHP_SELF: \"%s\"\n", $_SERVER['PHP_SELF']);
print '</pre>';
?>
Expected result:
----------------
I'd thought PHP_SELF should be possible to define explicitly through the
server
environment, without other variables affecting it's value. How come is it
so that
in the apache/mod_php mode both SCRIPT_NAME and PHP_SELF contain the same
value?
This does not seem to be possible in the FastCGI environment, at least when
using
php-fpm.
--
Edit bug report at https://bugs.php.net/bug.php?id=55209&edit=1
--
Try a snapshot (PHP 5.2):
https://bugs.php.net/fix.php?id=55209&r=trysnapshot52
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=55209&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=55209&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=55209&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=55209&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=55209&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=55209&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=55209&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=55209&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=55209&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=55209&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=55209&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=55209&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=55209&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=55209&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=55209&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=55209&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=55209&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=55209&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=55209&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=55209&r=mysqlcfg
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=55209&r=trysnapshot54