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

2015-01-24信息快讯网

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

“PHP_SELF”
当前正在执行脚本的文件名,与 document root 相关。举例来说,在 URL 地址为 http://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程序rlFB接的地址都多出一cgi-system恚但是程序的configK]有},查了查Y料才lF是SCRIPT_NAME和PHP_SELF不同造成的}。
通常在本Cy $_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分页时出现的Fatal error的解决方法
zend api扩展的php对象的autoload工具
ThinkPHP采用模块和操作分析
PHP学习之数组值的操作
PHP学习之数组的定义和填充
深入理解PHP原理之Session Gc的一个小概率Notice
The specified CGI application misbehaved by not returning a complete set of HTTP headers
php中突破基于HTTP_REFERER的防盗链措施(stream_context_create)
Zend Studio (eclipse)使用速度优化方法
php expects parameter 1 to be resource, array given 错误
8个出色的WordPress SEO插件收集
php提交表单时判断 if($_POST[submit])与 if(isset($_POST[submit])) 的区别
php5 apache 2.2 webservice 创建与配置(java)
php中使用ExcelFileParser处理excel获得数据(可作批量导入到数据库使用)
由php的call_user_func传reference引发的思考
PHP连接SQLServer2005 的问题解决方法
php $_SERVER["REQUEST_URI"]获取值的通用解决方法
不要轻信 PHP_SELF的安全问题
php getsiteurl()函数
PHP 内存缓存加速功能memcached安装与用法
用PHP读取flv文件的播放时间长度
用php将任何格式视频转为flv的代码
ajax php 实现写入数据库
php download.php实现代码 跳转到下载文件(response.redirect)
PHP has encountered an Access Violation at 7C94BD02解决方法
PHP 实现多服务器共享 SESSION 数据
彻底杜绝PHP的session cookie错误
php Sql Server连接失败问题及解决办法
PHP 配置文件中open_basedir选项作用
php mysql Errcode: 28 终极解决方法
php ignore_user_abort与register_shutdown_function 使用方法
php MsSql server时遇到的中文编码问题
PHP中查询SQL Server或Sybase时TEXT字段被截断的解决方法
PHP $_SERVER详解
©2014-2024 dbsqp.com