|  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: -
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
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.
Block user comment
Status: Assign to:
Bug Type:
From: andy at aiir dot com
New email:
PHP Version: OS:


 [2018-12-06 16:59 UTC] andy at aiir dot com
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.


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Jul 31 09:01:23 2021 UTC