From:             chris at w3style dot co dot uk
Operating system: Mac OS X
PHP version:      5.2.3
PHP Bug Type:     CGI related
Bug description:  SCRIPT_NAME breaks when a slash follows filename.php in URL

Description:
------------
When comparing the values held in $_SERVER['SCRIPT_NAME'] in CGI and 
SAPI in PHP 5.2.3, there's an obvious bug in the CGI version.

It works fine when the .php is the end of the URL, but in the case you 
use a URL like the following it breaks:

http://site.com/script.php/some/extra/info

Without the slash:

[SCRIPT_NAME] => /~d11wtq/Router/demo.php

With the slash:

[SCRIPT_NAME] => tq/Sites/Router/demo.php

This is probably because PHP is trying to truncate the wrong 
environment variable when producing the string.  The path on disk is:

/Users/d11wtq/Sites/Router/demo.php

You'll notice that the length of the incorrect string is actually the 
same as the length of the correct string, which is why I make this 
assumption.

I have found the following PHP code offers a suitable workaround until 
this bug is fixed:

<?php

if (isset($_SERVER["SCRIPT_NAME"]))
{
  if (isset($_SERVER["ORIG_PATH_INFO"]))
  {
    $len = strlen($_SERVER["SCRIPT_NAME"]);
    if (($tmp = substr($_SERVER["ORIG_PATH_INFO"], 0, $len)) != 
$_SERVER["SCRIPT_NAME"])
    {
      $_SERVER["SCRIPT_NAME"] = $tmp;
    }
  }
}

?>

Reproduce code:
---------------
Not needed, the description explains it nicely :)

Expected result:
----------------
$_SERVER["SCRIPT_NAME"] should contain the virtual path to the file in 
both cases.  This should be:

~d11wtq/Router/demo.php


Actual result:
--------------
SCRIPT_NAME contains a bogus string when run under CGI, but only if 
there's a slash after the .php suffix.

-- 
Edit bug report at http://bugs.php.net/?id=41793&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=41793&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=41793&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=41793&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=41793&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=41793&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=41793&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=41793&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=41793&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=41793&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=41793&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=41793&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=41793&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=41793&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=41793&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=41793&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=41793&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=41793&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=41793&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=41793&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=41793&r=mysqlcfg

Reply via email to