php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66711 PHP_SELF has trailing slash for index.php
Submitted: 2014-02-13 22:32 UTC Modified: 2021-08-17 11:28 UTC
Votes:3
Avg. Score:3.7 ± 0.9
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: cmbecker69 at gmx dot de Assigned: cmb (profile)
Status: Closed Package: Built-in web server
PHP Version: 5.5.9 OS: Windows 7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: cmbecker69 at gmx dot de
New email:
PHP Version: OS:

 

 [2014-02-13 22:32 UTC] cmbecker69 at gmx dot de
Description:
------------
When requesting the document root, the built-in webserver appends
a superfluous and AFAICT erroneous slash to $_SERVER['PHP_SELF'].

This does neither happen when the file index.php is requested
directly, nor when a subdirectory is requested.

Test script:
---------------
<?php

var_dump($_SERVER['PHP_SELF']);

Expected result:
----------------
string(11) "/index.php/"

Actual result:
--------------
string(10) "/index.php"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-02-14 19:34 UTC] cmbecker69 at gmx dot de
I have to correct myself: it always happens when a trailing slash
is appended to the URL.

From what I can tell, this issue is related to the stat() call in
php_cli_server_request_translate_vpath().  While *nix (tested on
Cygwin) returns 0 for an existing directory with a trailing slash,
Windows returns -1 (on Windows the directory separator is properly
changed to backslash).  This bypasses the break on line 1509, and
causes prev_path to be changed to "\", what is later assigned to
request->path_info.

In sapi_cli_server_register_variables() PHP_SELF is finally set by
using the wrong path_info[2].

My knowledge of C is limited, so I'm not able to appropriately fix
the bug; however, I've sent a respective phpt to the QA list[3].

[1] <http://lxr.php.net/xref/PHP_5_5/sapi/cli/php_cli_server.c#1486>
[2] <http://lxr.php.net/xref/PHP_5_5/sapi/cli/php_cli_server.c#790>
[3] <http://news.php.net/php.qa/67222>
 [2014-03-03 18:38 UTC] pajoye@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: pajoye
 [2014-04-05 01:48 UTC] jakoch at web dot de
i think this is a duplicate of the slash-bug, reported at
https://bugs.php.net/bug.php?id=66191 
sadly the issue was closed without even checking it.
 [2014-04-05 11:07 UTC] cmbecker69 at gmx dot de
I have just noticed, that the expected and actual results given
above are permuted. That should have been:

Expected result:
----------------
string(10) "/index.php"

Actual result:
--------------
string(11) "/index.php/"
 [2014-04-05 11:34 UTC] cmbecker69 at gmx dot de
> i think this is a duplicate of the slash-bug, reported at
> https://bugs.php.net/bug.php?id=66191

No, the issues are not related. I have filed a feature request
regarding the "trailing slash" redirect (#67027), because I assume
it is futile to add comments to an already closed bug report.
 [2017-10-24 07:37 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: pajoye +Assigned To:
 [2021-08-17 11:28 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-08-17 11:28 UTC] cmb@php.net
Oh, this is apparently fixed as of PHP 7.0.0.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 11:01:34 2025 UTC