Skip to content

Commit ac789e0

Browse files
committed
Fixed Bug #60180 ($_SERVER["PHP_SELF"] incorrect)
1 parent 58a134f commit ac789e0

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ PHP NEWS
99
(Laruence)
1010
. Fixed bug #60115 (memory definitely lost in cli server). (Laruence)
1111
. Fixed bug #60146 (Last 2 lines of page not being output). (Laruence)
12+
. Fixed bug #60180 ($_SERVER["PHP_SELF"] incorrect). (Laruence)
1213

1314
- Core:
1415
. Fixed bug #60120 (proc_open's streams may hang with stdin/out/err when

sapi/cli/php_cli_server.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,13 +579,21 @@ static void sapi_cli_server_register_variables(zval *track_vars_array TSRMLS_DC)
579579
}
580580
sapi_cli_server_register_variable(track_vars_array, "REQUEST_URI", client->request.request_uri TSRMLS_CC);
581581
sapi_cli_server_register_variable(track_vars_array, "REQUEST_METHOD", SG(request_info).request_method TSRMLS_CC);
582-
sapi_cli_server_register_variable(track_vars_array, "PHP_SELF", client->request.vpath TSRMLS_CC);
582+
sapi_cli_server_register_variable(track_vars_array, "SCRIPT_NAME", client->request.vpath TSRMLS_CC);
583583
if (SG(request_info).path_translated) {
584584
sapi_cli_server_register_variable(track_vars_array, "SCRIPT_FILENAME", SG(request_info).path_translated TSRMLS_CC);
585585
}
586586
if (client->request.path_info) {
587587
sapi_cli_server_register_variable(track_vars_array, "PATH_INFO", client->request.path_info TSRMLS_CC);
588588
}
589+
if (client->request.path_info_len) {
590+
char *tmp;
591+
spprintf(&tmp, 0, "%s%s", client->request.vpath, client->request.path_info);
592+
sapi_cli_server_register_variable(track_vars_array, "PHP_SELF", tmp TSRMLS_CC);
593+
efree(tmp);
594+
} else {
595+
sapi_cli_server_register_variable(track_vars_array, "PHP_SELF", client->request.vpath TSRMLS_CC);
596+
}
589597
if (client->request.query_string) {
590598
sapi_cli_server_register_variable(track_vars_array, "QUERY_STRING", client->request.query_string TSRMLS_CC);
591599
}
@@ -1330,6 +1338,16 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque
13301338
request->path_translated = buf;
13311339
request->path_translated_len = q - buf;
13321340
}
1341+
#ifdef PHP_WIN32
1342+
{
1343+
uint i = 0;
1344+
for (;i<request->vpath_len;i++) {
1345+
if (request->vpath[i] == '\\') {
1346+
request->vpath[i] = '/';
1347+
}
1348+
}
1349+
}
1350+
#endif
13331351
request->sb = sb;
13341352
} /* }}} */
13351353

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
--TEST--
2+
Bug #60180 ($_SERVER["PHP_SELF"] incorrect)
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc";
6+
?>
7+
--FILE--
8+
<?php
9+
include "php_cli_server.inc";
10+
php_cli_server_start('var_dump($_SERVER["PHP_SELF"], $_SERVER["SCRIPT_NAME"], $_SERVER["PATH_INFO"], $_SERVER["QUERY_STRING"]);', TRUE);
11+
12+
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
13+
$port = intval($port)?:80;
14+
15+
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
16+
if (!$fp) {
17+
die("connect failed");
18+
}
19+
20+
if(fwrite($fp, <<<HEADER
21+
GET /foo/bar?foo=bar HTTP/1.1
22+
Host: {$host}
23+
24+
25+
HEADER
26+
)) {
27+
while (!feof($fp)) {
28+
echo fgets($fp);
29+
}
30+
}
31+
32+
fclose($fp);
33+
34+
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
35+
if (!$fp) {
36+
die("connect failed");
37+
}
38+
39+
40+
if(fwrite($fp, <<<HEADER
41+
GET /index.php/foo/bar/?foo=bar HTTP/1.0
42+
Host: {$host}
43+
44+
45+
HEADER
46+
)) {
47+
while (!feof($fp)) {
48+
echo fgets($fp);
49+
}
50+
}
51+
52+
fclose($fp);
53+
54+
?>
55+
--EXPECTF--
56+
HTTP/1.1 200 OK
57+
Host: %s
58+
Connection: closed
59+
X-Powered-By: PHP/%s
60+
Content-type: text/html
61+
62+
string(18) "/index.php/foo/bar"
63+
string(10) "/index.php"
64+
string(8) "/foo/bar"
65+
string(7) "foo=bar"
66+
HTTP/1.0 200 OK
67+
Host: %s
68+
Connection: closed
69+
X-Powered-By: PHP/%s
70+
Content-type: text/html
71+
72+
string(19) "/index.php/foo/bar/"
73+
string(10) "/index.php"
74+
string(9) "/foo/bar/"
75+
string(7) "foo=bar"

0 commit comments

Comments
 (0)