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: -
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:
Status: Open Package: Built-in web server
PHP Version: 7.2.13 OS: *nix
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Dec 10 02:01:24 2018 UTC