教学之友,学习之友。

站长教学网

当前位置: 站长教学网 > 网站编程 > PHP教程 >

获取PHP_SELF|SCRIPT_NAME|REQUEST_URI的区别

时间:2013-04-28 14:19来源:未知 作者:ken 点击:

$_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] 在用法上是非常相似的,他们返回的都是与当前正在使用的页面地址有关的信息,这里列出一些相关的例子,帮助确定哪些是在你的脚本最适合的。
$_SERVER[’PHP_SELF’]
http://www.eduyo.com/example/ — – — /example/index.php
http://www.eduyo.com/example/index.php — – — /example/index.php
http://www.eduyo.com/example/index.php?a=test — – — /example/index.php
http://www.eduyo.com/example/index.php/dir/test — – — /dir/test
当我们使用$_SERVER['PHP_SELF']的时候,无论访问的URL地址是否有index.php,它都会自动的返回 index.php.但是如果在文件名后面再加斜线的话,就会把后面所有的内容都返回在$_SERVER['PHP_SELF']。
$_SERVER['REQUEST_URI']
http://www.eduyo.com/example/ — – — /
http://www.eduyo.com/example/index.php — – — /example/index.php
http://www.eduyo.com/example/index.php?a=test — – — /example/index.php?a=test
http://www.eduyo.com/example/index.php/dir/test — – — /example/index.php/dir/test
$_SERVER['REQUEST_URI']返回的是我们在URL里写的精确的地址,如果URL只写到”/”,就返回 “/”
$_SERVER['SCRIPT_NAME']
http://www.eduyo.com/example/ — – — /example/index.php
http://www.eduyo.com/example/index.php — – — /example/index.php
http://www.eduyo.com/example/index.php — – — /example/index.php
http://www.eduyo.com/example/index.php/dir/test — – — /example/index.php
在所有的返回中都是当前的文件名/example/index.php

(责任编辑:ken)
TAG标签: php
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
注册登录:不允许匿名留言,登录后留言无需输入验证码。
栏目列表
最新内容