QUERY_STRING、REQUEST_URI、SCRIPT_NAME、PHP_SELF区别
清泛原创
实例:
1、http://localhost/aaa/ (打开aaa中的index.php)
$_SERVER['QUERY_STRING'] = "";
$_SERVER['REQUEST_URI'] = "/aaa/";
$_SERVER['SCRIPT_NAME'] = "/aaa/index.php";
$_SERVER['PHP_SELF'] = "/aaa/index.php";
2、http://localhost/aaa/index.php?p=222&q=333(带参数)
$_SERVER['QUERY_STRING'] = "p=222&q=333";
$_SERVER['REQUEST_URI'] = "/aaa/index.php?p=222&q=333";
$_SERVER['SCRIPT_NAME'] = "/aaa/index.php";
$_SERVER['PHP_SELF'] = "/aaa/index.php";
3、http://localhost/tag/test → http://localhost/index.php?m=tag&tag=test(URL重写)
$_SERVER['QUERY_STRING'] = "m=tag&tag=test";
$_SERVER['REQUEST_URI'] = "/tag/test";
$_SERVER['SCRIPT_NAME'] = "/index.php";
$_SERVER['PHP_SELF'] = "/index.php";
由实例可知:
$_SERVER["QUERY_STRING"] 获取查询 语句,实例中可知,获取的是?后面的值
$_SERVER["REQUEST_URI"] 获取 http://localhost 后面的值,包括/
$_SERVER["SCRIPT_NAME"] 获取当前脚本的路径,如:index.php
$_SERVER["PHP_SELF"] 当前正在执行脚本的文件名
1、http://localhost/aaa/ (打开aaa中的index.php)
$_SERVER['QUERY_STRING'] = "";
$_SERVER['REQUEST_URI']
$_SERVER['SCRIPT_NAME']
$_SERVER['PHP_SELF']
2、http://localhost/aaa/index.php?p=222&q=333(带参数)
$_SERVER['QUERY_STRING'] = "p=222&q=333";
$_SERVER['REQUEST_URI']
$_SERVER['SCRIPT_NAME']
$_SERVER['PHP_SELF']
3、http://localhost/tag/test → http://localhost/index.php?m=tag&tag=test(URL重写)
$_SERVER['QUERY_STRING'] = "m=tag&tag=test";
$_SERVER['REQUEST_URI']
$_SERVER['SCRIPT_NAME']
$_SERVER['PHP_SELF']
由实例可知:
$_SERVER["QUERY_STRING"]
$_SERVER["REQUEST_URI"]
$_SERVER["SCRIPT_NAME"]
$_SERVER["PHP_SELF"]