php 区别: $_SERVER['SCRIPT_NAME'] 和 $_SERVER['PHP_SELF']

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6470748/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:28:51  来源:igfitidea点击:

Difference between: $_SERVER['SCRIPT_NAME'] and $_SERVER['PHP_SELF']

php

提问by Jim

What is the difference between:

有什么区别:

$_SERVER['SCRIPT_NAME']

and

$_SERVER['PHP_SELF']

Thank you.

谢谢你。

回答by Michael Irigoyen

They should contain the same information. However, historically and technically speaking, there is a difference between the two.

它们应该包含相同的信息。但是,从历史和技术上讲,两者之间存在差异。

SCRIPT_NAMEis defined in the CGI 1.1 specification, and therefore is a standard. This means it should be available no matter what scripting language you're using.

SCRIPT_NAME在 CGI 1.1 规范中定义,因此是一个标准。这意味着无论您使用哪种脚本语言,它都应该可用。

PHP_SELFis implemented directly by PHP, and as long as you're programming in PHP, it will be there.

PHP_SELF是直接用PHP实现的,只要你用PHP编程,它就在那里。

回答by regilero

Most of the time it's the same, but $_SERVER['SCRIPT_NAME']is less spoofable than $_SERVER['PHP_SELF'], so you should use SCRIPT_NAMEif you want to reuse that data somewhere on your output.

大多数情况下它是相同的,但$_SERVER['SCRIPT_NAME']比 更不易被欺骗$_SERVER['PHP_SELF'],因此如果您想在输出的某处重用该数据,则应使用SCRIPT_NAME

Check that articleon different results obtained.

检查获得的不同结果的文章