php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77253 PHP_SELF value differs based on path to router script
Submitted: 2018-12-06 16:59 UTC Modified: 2021-08-29 04:22 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: andy at aiir dot com Assigned: cmb (profile)
Status: No Feedback Package: Built-in web server
PHP Version: 7.2.13 OS: *nix
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: andy at aiir dot com
New email:
PHP Version: OS:

 

 [2018-12-06 16:59 UTC] andy at aiir dot com
Description:
------------
When running the PHP internal web server, the location of the router script affects the output of the PHP_SELF value in an unusual way.

If I run PHP from the folder with the script in:

$ php -S 0:8080 index.php

And then call http://localhost:8080/, the value for PHP_SELF is `/index.php`. If I run the script from a parent directory (or any other location that differs from the script), e.g.:

$ php -S 0:8080 src/index.php

The value for PHP_SELF when request http://localhost:8080/foo/bar will be `/foo/bar`.

I'm not certain if this behaviour is intentional or not, but if it is, why is it this way? We noticed this issue because it breaks a lot of popular routing libraries as they strip the content of PHP_SELF from the variable they discern the path from, so it fails to route requests correctly.


Test script:
---------------
<?php echo $_SERVER['PHP_SELF'];

Expected result:
----------------
Expect the PHP_SELF value to always provide a path to the script, not change between this and the web requested path.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-08-17 11:59 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-08-17 11:59 UTC] cmb@php.net
I cannot reproduce this with PHP-7.4 on Windows.  Is this still an
issue for you with any of the actively supported PHP versions[1]?

[1] <https://www.php.net/supported-versions.php>
 [2021-08-29 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 03:01:29 2024 UTC