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

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

问题描述

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

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_URI PATH_INFO 等获得,但我想决定哪个是最可靠的。有没有人知道(或知道在哪里找到) PHP_SELF PATH_INFO SCRIPT_NAME REQUEST_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!

注意:我不得不添加空格,因为看到下划线, 。

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

已更新:修正了空格。

推荐答案

PHP文档可以告诉您区别:


'PHP_SELF'

'PHP_SELF'


当前执行的脚本的文件名,相对于文档根目录。例如,在地址 $ _ SERVER ['PHP_SELF'] rel = nofollow noreferrer> 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'


PATH_INFO似乎没有文件...

PATH_INFO doesn't seem to be documented...

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

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