PHP_SELF vs PATH_INFO vs SCRIPT_NAME vs REQUEST_URI [英] PHP_SELF vs PATH_INFO vs SCRIPT_NAME vs REQUEST_URI

查看:18
本文介绍了PHP_SELF vs PATH_INFO vs SCRIPT_NAME vs REQUEST_URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 CodeIgniter 中构建一个 PHP 应用程序.CodeIgniter 将所有请求发送到主控制器:index.php.但是,我不喜欢在 URI 中看到 index.php.例如,http://www.example.com/faq/whatever 将路由到 http://www.example.com/index.php/faq/whatever.我需要一种可靠的方式让脚本知道它的地址是什么,这样它就会知道如何处理导航.根据 CodeIgniter 文档,我使用了 mod_rewrite.

I am building a PHP application in CodeIgniter. CodeIgniter sends all requests to the main controller: index.php. However, I don't like to see index.php in the URI. For example, http://www.example.com/faq/whatever will route to http://www.example.com/index.php/faq/whatever. I need a reliable way for a script to know what it's address is, so it will know what to do with the navigation. I've used mod_rewrite, as per CodeIgniter documentation.

规则如下:

RewriteEngine on
RewriteCond $1 !^(images|inc|favicon.ico|index.php|robots.txt)
RewriteRule ^(.*)$ /index.php/$1 [L] 

通常,我只会检查 php_self,但在这种情况下,它始终是 index.php.我可以从 REQUEST_URIPATH_INFO 等获取它,但我正在尝试决定哪个最可靠.有谁知道(或知道在哪里可以找到)PHP_SELFPATH_INFOSCRIPT_NAMEREQUEST_URI 之间的真正区别?感谢您的帮助!

Normally, I would just check php_self, but in this case it's always index.php. I can get it from REQUEST_URI, PATH_INFO, etc., but I'm trying to decide which will be most reliable. Does anyone know (or know where to find) the real difference between PHP_SELF, PATH_INFO, SCRIPT_NAME, and REQUEST_URI? Thanks for your help!

注意:我不得不添加空格,因为 SO 看到下划线,并且出于某种原因将其设为斜体.

Note: I've had to add spaces, as SO sees the underscore, and makes it italic for some reason.

更新:修正了空格.

推荐答案

PHP 文档 可以告诉你区别:

'PHP_SELF'

当前正在执行的脚本的文件名,相对于文档根目录.例如,$_SERVER['PHP_SELF'] 在地址http://example.com/test.php/foo.bar 将是 /test.php/foo.bar.__FILE__ 常量包含当前(即包括)文件.如果 PHP 作为命令行处理器运行,则此变量包含自 PHP 4.3.0 以来的脚本名称.以前它不可用.

The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar. The __FILE__ constant contains the full path and filename of the current (i.e. included) file. If PHP is running as a command-line processor this variable contains the script name since PHP 4.3.0. Previously it was not available.

'SCRIPT_NAME'

包含当前脚本的路径.这对于需要指向自身的页面很有用.__FILE__ 常量包含当前(即包含)文件.

Contains the current script's path. This is useful for pages which need to point to themselves. The __FILE__ constant contains the full path and filename of the current (i.e. included) file.

'REQUEST_URI'

为访问此页面而提供的 URI;例如,'/index.html'.

The URI which was given in order to access this page; for instance, '/index.html'.

PATH_INFO 似乎没有记录...

PATH_INFO doesn't seem to be documented...

这篇关于PHP_SELF vs PATH_INFO vs SCRIPT_NAME vs REQUEST_URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆