$_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] 在使用方法上是很相似的,他们返回的都是与当前正在使用的页面地址有关的信息。这里列出一些相关的样例,帮助确定哪些是在你的脚本最适合的。

$_SERVER[’PHP_SELF’]

  • http://www.yoursite.com/example/ — – — /example/index.php
  • http://www.yoursite.com/example/index.php — – — /example/index.php
  • http://www.yoursite.com/example/index.php?a=test — – — /example/index.php
  • http://www.yoursite.com/example/index.php/dir/test — – — /dir/test

当我们使用$_SERVER['PHP_SELF']的时候,不管訪问的URL地址是否有index.php,它都会自己主动的返回 index.php.可是假设在文件名称后面再加斜线的话,就会把后面全部的内容都返回在$_SERVER['PHP_SELF']。

$_SERVER['REQUEST_URI']

  • http://www.yoursite.com/example/ — – — /
  • http://www.yoursite.com/example/index.php — – — /example/index.php
  • http://www.yoursite.com/example/index.php?a=test — – — /example/index.php?a=test
  • http://www.yoursite.com/example/index.php/dir/test — – — /example/index.php/dir/test

$_SERVER['REQUEST_URI']返回的是我们在URL里写的精确的地址,假设URL仅仅写到”/”,就返回 “/”

$_SERVER['SCRIPT_NAME']

  • http://www.yoursite.com/example/ — – — /example/index.php
  • http://www.yoursite.com/example/index.php — – — /example/index.php
  • http://www.yoursite.com/example/index.php — – — /example/index.php
  • http://www.yoursite.com/example/index.php/dir/test — – — /example/index.php

在全部的返回中都是当前的文件名称/example/index.php

$_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] 在使用方法上是很相似的。他们返回的都是与当前正在使用的页面地址有关的信息。这里列出一些相关的样例,帮助确定哪些是在你的脚本最适合的。

$_SERVER[’PHP_SELF’]

  • http://www.yoursite.com/example/ — – — /example/index.php
  • http://www.yoursite.com/example/index.php — – — /example/index.php
  • http://www.yoursite.com/example/index.php?a=test — – — /example/index.php
  • http://www.yoursite.com/example/index.php/dir/test — – — /dir/test

当我们使用$_SERVER['PHP_SELF']的时候。不管訪问的URL地址是否有index.php,它都会自己主动的返回 index.php.可是假设在文件名称后面再加斜线的话,就会把后面全部的内容都返回在$_SERVER['PHP_SELF']。

$_SERVER['REQUEST_URI']

  • http://www.yoursite.com/example/ — – — /
  • http://www.yoursite.com/example/index.php — – — /example/index.php
  • http://www.yoursite.com/example/index.php?

    a=test — – — /example/index.php?a=test

  • http://www.yoursite.com/example/index.php/dir/test — – — /example/index.php/dir/test

$_SERVER['REQUEST_URI']返回的是我们在URL里写的精确的地址,假设URL仅仅写到”/”。就返回 “/”

$_SERVER['SCRIPT_NAME']

  • http://www.yoursite.com/example/ — – — /example/index.php
  • http://www.yoursite.com/example/index.php — – — /example/index.php
  • http://www.yoursite.com/example/index.php — – — /example/index.php
  • http://www.yoursite.com/example/index.php/dir/test — – — /example/index.php

在全部的返回中都是当前的文件名称/example/index.php

PHP_SELF、 SCRIPT_NAME、 REQUEST_URI差别的更多相关文章

  1. PATH_INFO, SCRIPT_NAME, REQUEST_URI区别示例

     

  2. PHP_SELF变量解析和重复路径解决

    最近升级PHP到PHP7版本,并重新部署了新的Nginx,启动的时候发现了一个问题,全局变量$_SERVER['PHP_SELF']的值发生了改变,从而影响到代码的功能.因此我们来了解下$_SERVE ...

  3. CodeIgniter_2 路由中定义伪静态 直接映射到相关的控制器

    某些情况下 隐藏路径信息 使用伪静态定义: RewriteRule ^no/torrent(.*)$ /index.php/torrent/doit/$1 CodeIgniter会自动识别到 no 控 ...

  4. PHP: Browser, Operating System (OS), Device, and Language Detect

    https://github.com/sinergi/php-browser-detector Device.php: <!DOCTYPE html> <html> <h ...

  5. PHP中级程序员常见面试题

    1).写一个函数,从一个标准url里取出文件的扩展名,需要取出php或.php <?php $a="http://www.test.com.cn:88/abc/de/fg.php?id ...

  6. FastCGI协议分析

    不知道什么时候,就开始有了让HomeServer支持PHP的念头.于是分析起了FastCGI协议.FastCGI用于WebServer与WebApplication之间的通讯,例如Apache与PHP ...

  7. PHP $_SERVER['PHP_SELF']、$_SERVER['SCRIPT_NAME'] 与 $_SERVER['REQUEST_URI'] 之间的区别

    PHP $_SERVER['PHP_SELF'].$_SERVER['SCRIPT_NAME'] 与 $_SERVER['REQUEST_URI'] $_SERVER['PHP_SELF'].$_SE ...

  8. PHP_SELF、 SCRIPT_NAME、 REQUEST_URI区别

    $_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] 在用法上是非常相似的,他们返回的都是与当前正在使用的页面地址有关的 ...

  9. $_SERVER["SCRIPT_NAME"]、$_SERVER["PHP_SELF"]、$_SERVER["QUERY_STRING"]、$_SERVER["REQUEST_URI"]

    1.$_SERVER["SCRIPT_NAME"] 说明:包含当前脚本的路径 2.$_SERVER["PHP_SELF"] 说明:当前正在执行脚本的文件名 3. ...

随机推荐

  1. ubuntu 10.04安装qtcreator并汉化

    最近最的项目中需要做出来一个带有界面的demo,所以想到了用qt做个简单的demo! 于是在ubuntu上安装了qt,很简单apt-get apt-get install qtcreator 大概几百 ...

  2. Android-Cannot merge new index 66195 into a non-jumbo instruction的解决的方法

    转载请注明来源:http://blog.csdn.net/goldenfish1919/article/details/33729679 用eclispe打包的时候报错: [2014-06-23 13 ...

  3. Swift - 通过url地址打开web页面

    通过UIApplication.sharedApplication().openURL()方法,可以使用浏览器打开相应的网页. 1 2 3 var urlString = "http://h ...

  4. Android ListView 单条刷新方法实践及原理解析

    对于使用listView配合adapter进行刷新的方法大家都不陌生,先刷新adapter里的数据,然后调用notifydatasetchange通知listView刷新界面. 方法虽然简单,但这里面 ...

  5. C# - 重写虚方法

    项目目录: 创建教师类(Teacher),虚方法有Teach(); 创建学生类(Student),重写的方法是Teach(); 教师类: · 加上关键字 Virtual 就是声明可以重写此方法. us ...

  6. ajax和json详解

    responseText  属性以字符串形式返回HTTP响应. responseXML  属性以XML形式返回HTTP响应. JSON.stringify 函数 (JavaScript)  将 Jav ...

  7. 【iOS开发-31】UITabBar背景、icon图标颜色、被选中背景设置以及隐藏UITabBar的两种方式

    一.对UITabBar背景和icon图标的一些设置 (1)由于直接给UITabBar设置的背景颜色显示的不纯.半透明的感觉,所以,有时候我们能够直接利用纯色的图片作为背景达到想要的效果. (2)给ic ...

  8. React-TodoList

    React入门最好的学习实例-TodoList 前言 React 的核心思想是:封装组件,各个组件维护自己的状态和 UI,当状态变更,自动重新渲染整个组件. 最近前端界闹的沸沸扬扬的技术当属react ...

  9. 一个计算器的C语言实现

    今天在读<编译原理及实践>时.看到了一个简单的整数计算器的实现. 依照书上的思路,我略微进行了扩展: 1.从整数计算器扩展到小数计算器. 2.支持除法 3.支持空字符. 执行效果例如以下: ...

  10. 14.4.7 Configuring the Number of Background InnoDB IO Threads 配置 后台InnoDB IO Threads的数量

    14.4.7 Configuring the Number of Background InnoDB IO Threads 配置 后台InnoDB IO Threads的数量 InnoDB 使用bac ...