PHP $_SERVER['PHP_SELF']

$_SERVER['PHP_SELF'] 表示当前 php 文件相对于网站根目录的位置地址,与 document root 相关。

假设我们有如下网址,$_SERVER['PHP_SELF']得到的结果分别为:

http://localhost/php/ :/php/index.php
http://localhost/php/index.php :/php/index.php
http://localhost/php/index.php?test=foo :/php/index.php
http://localhost/php/index.php/test/foo :/php/index.php/tes...