示例 http://localhost/demo/t.php/test1/test2/?a=123&b=234

/demo/t.php //$_SERVER['SCRIPT_NAME']
/test1/test2/ //$_SERVER['PATH_INFO']
/demo/t.php/test1/test2/ //$_SERVER['PHP_SELF']
a=123&b=234 //$_SERVER['QUERY_STRING']
/demo/t.php/test1/test2/?a=123&b=234 //$_SERVER['REQUEST_URI']

如上的示例中:
$_SERVER['SCRIPT_NAME']获得的是当前程序的目录和文件名
$_SERVER['PATH_INFO']获得的是.php以后至?号之前的路径
$_SERVER['PHP_SELF']等于$_SERVER['SCRIPT_NAME'] + $_SERVER['PATH_INFO']
$_SERVER['QUERY_STRING']是?之后的所有参数字符串
$_SERVER['REQUEST_URI']是整个url路径,可以行于以下2种:

  1. $_SERVER['SCRIPT_NAME'] + $_SERVER['PATH_INFO'] + $_SERVER['QUERY_STRING']
  2. $_SERVER['PHP_SELF'] + $_SERVER['QUERY_STRING']

标签: $_server[]函数

添加新评论