PHP_SELF,SCRIPT_NAME,REQUEST_URI区别 PHP_SELF,SCRIPT_NAME,REQUEST_URI区别

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

PHP_SELF,SCRIPT_NAME,REQUEST_URI区别 PHP_SELF,SCRIPT_NAME,REQUEST_URI区别

  2021-03-19 我要评论
想了解PHP_SELF,SCRIPT_NAME,REQUEST_URI区别的相关内容吗,在本文为您仔细讲解PHP_SELF,SCRIPT_NAME,REQUEST_URI区别的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:PHP_SELF,SCRIPT_NAME,REQUEST_URI,下面大家一起来学习吧。

$_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

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们