欢迎来到代码驿站!

PHP代码

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

php中$_SERVER[PHP_SELF] 和 $_SERVER[SCRIPT_NAME]之间的区别

时间:2021-06-18 08:44:18|栏目:PHP代码|点击:
“PHP_SELF”
当前正在执行脚本的文件名,与 document root 相关。举例来说,在 URL 地址为 https://www.jb51.net/test.php/foo.bar 的脚本中使用 $_SERVER['PHP_SELF'] 将会得到 /test.php/foo.bar 这个结果。__FILE__ 常量包含当前(例如包含)文件的绝对路径和文件名。

“SCRIPT_NAME”
包含当前脚本的路径。这在页面需要指向自己时非常有用。__FILE__ 包含当前文件的绝对路径和文件名(例如包含文件)。

主要的原因如像:$_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];

找到更好的原因是:
今天在Dreamhost上安?b一套PHP程序?r?l?F?B接的地址都??多出一??cgi-system?恚?但是程序的config?K?]有???},查了查?Y料才?l?F是SCRIPT_NAME和PHP_SELF不同造成的???}。
通常在本?C?y? $_SERVER['SCRIPT_NAME'] 跟 $_SERVER['PHP_SELF'] 大概看不出有什?N不同,因?榇蟛糠值?PHP不是以CGI模式?\行的。
但 DreamHost 上的 PHP 是以 CGI 方式?\行,二者就有明?@不同的差??。
echo $_SERVER['SCRIPT_NAME']; // (/cgi-system/php.cgi)
echo $_SERVER['PHP_SELF']; // (/admin/test.php)

从http://lists.nyphp.org/pipermail/talk/2005-July/015339.html 发现了一个说明。老外说的。

SCRIPT_NAME solves all the problems mentioned
in this thread - it's just the script name, without any extra garbage
that might be tacked on by the user. PHP_SELF explicitly includes that
extra garbage, so solutions in this thread that involve stripping the
garbage off of PHP_SELF to make it safe are really, really missing the
point - just use SCRIPT_NAME instead. Please don't use FORM ACTION=”";
according to the spec, what the browser does with that is undefined, so
even if it works in current browsers, it might not work in future ones

上一篇:PHP有序表查找之二分查找(折半查找)算法示例

栏    目:PHP代码

下一篇:PHP入门教程之字符串处理技巧总结(转换,过滤,解析,查找,截取,替换等)

本文标题:php中$_SERVER[PHP_SELF] 和 $_SERVER[SCRIPT_NAME]之间的区别

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

推荐教程

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

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

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

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

Copyright © 2020 代码驿站 版权所有