$_SERVER["QUERY_STRING"],$_SERVER["REQUEST_URI"],$_SERVER["SCRIPT_NAME"] 和$_SERVER["PHP_SELF"]

$_SERVER["QUERY_STRING"],$_SERVER["REQUEST_URI"],$_SERVER["SCRIPT_NAME"] 和$_SERVER["PHP_SELF"]

之间的区别

1,$_SERVER["QUERY_STRING"]

  说明:查询(query)的字符串

  2,$_SERVER["REQUEST_URI"]

  说明:访问此页面所需的URI

  3,$_SERVER["SCRIPT_NAME"]

  说明:包含当前脚本的路径

  4,$_SERVER["PHP_SELF"]

  说明:当前正在执行脚本的文件名

  实例:

 

  1,http://www.xxx.com/ (直接打开主页)

  结果:

  $_SERVER["QUERY_STRING"] = “”

  $_SERVER["REQUEST_URI"] = “/”

  $_SERVER["SCRIPT_NAME"] = “/index.php”

  $_SERVER["PHP_SELF"] = “/index.php”

 

  2,http://www.xxx.com/?p=222 (附带查询)

  结果:

  $_SERVER["QUERY_STRING"] = “p=222″

  $_SERVER["REQUEST_URI"] = “/?p=222″

  $_SERVER["SCRIPT_NAME"] = “/index.php”

  $_SERVER["PHP_SELF"] = “/index.php”

 

  3,http://www.xxx.com/index.php?p=222&q=u

  结果:

  $_SERVER["QUERY_STRING"] = “p=222&q=u”

  $_SERVER["REQUEST_URI"] = “/index.php?p=222&q=u”

  $_SERVER["SCRIPT_NAME"] = “/index.php”

  $_SERVER["PHP_SELF"] = “/index.php”

 

  $_SERVER["QUERY_STRING"]获取查询语句,实例中可知,获取的是?后面的值

  $_SERVER["REQUEST_URI"] 获取http://www.xxx.com后面的值,包括/

  $_SERVER["SCRIPT_NAME"] 获取当前脚本的路径,如:index.php

  $_SERVER["PHP_SELF"] 当前正在执行脚本的文件名

posted @ 2021-05-20 18:28  binbin_cloud  阅读(70)  评论(0编辑  收藏  举报