欢迎来到代码驿站!

PHP代码

当前位置:首页 > 软件编程 > PHP代码

PHP_SELF,SCRIPT_NAME,REQUEST_URI区别

时间:2021-07-15 09:28:40|栏目:PHP代码|点击:

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

$_SERVER['PHP_SELF']

复制代码 代码如下:

http://www.yoursite.com/example/ ― ?C ― /example/index.php
http://www.yoursite.com/example/index.php ― ?C ― /example/index.php
http://www.yoursite.com/example/index.php?a=test ― ?C ― /example/index.php
http://www.yoursite.com/example/index.php/dir/test ― ?C ― /dir/test

当我们使用$_SERVER['PHP_SELF']的时候,无论访问的URL地址是否有index.php,它都会自动的返回 index.php.但是如果在文件名后面再加斜线的话,就会把后面所有的内容都返回在$_SERVER['PHP_SELF']。

$_SERVER['REQUEST_URI']

复制代码 代码如下:

http://www.yoursite.com/example/ ― ?C ― /
http://www.yoursite.com/example/index.php ― ?C ― /example/index.php
http://www.yoursite.com/example/index.php?a=test ― ?C ― /example/index.php?a=test
http://www.yoursite.com/example/index.php/dir/test ― ?C ― /example/index.php/dir/test

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

$_SERVER['SCRIPT_NAME']

复制代码 代码如下:

http://www.yoursite.com/example/ ― ?C ― /example/index.php
http://www.yoursite.com/example/index.php ― ?C ― /example/index.php
http://www.yoursite.com/example/index.php ― ?C ― /example/index.php
http://www.yoursite.com/example/index.php/dir/test ― ?C ― /example/index.php

在所有的返回中都是当前的文件名/example/index.php

上一篇:PHP解析xml格式数据工具类示例

栏    目:PHP代码

下一篇:php获取一个变量的名字的方法

本文标题:PHP_SELF,SCRIPT_NAME,REQUEST_URI区别

本文地址:http://www.codeinn.net/misctech/157409.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有