【问题标题】:What is the difference between $_SERVER['REQUEST_URI'] and "$_SERVER['REQUEST_URI']" (note double quotes)?$_SERVER['REQUEST_URI'] 和 "$_SERVER['REQUEST_URI']" 有什么区别(注意双引号)?
【发布时间】:2015-03-10 11:58:55
【问题描述】:

我在http://example.com/test/sub/index.php 文件中有一些命令来回显 php 派生值。 对于地址栏中的以下地址,我得到: http://example.com/test/sub/index.php/blahblah

$_SERVER[SCRIPT_NAME]: /test/sub/index.php

$_SERVER['HTTP_HOST']: example.com

$_SERVER['PHP_SELF']: /test/sub/index.php/blahblah

$_SERVER['REQUEST_URl']:

"$_SERVER['REQUEST_URI']": /test/sub/index.php/blahblah

如果使用不带引号的“REQUEST_URl”,为什么会返回 null?

我正在尝试在 .htaccess 中调试我的 RewriteRule,我需要“REQUEST_URl”将路径返回为“/test/sub/index.php/blahblah”,或者如果我能获得“index.php”会更好/废话”

【问题讨论】:

  • 超全局变量总是大写的!例如$_SERVER
  • 您使用的是 REQUEST_URL(带有小写的“L”)。
  • 谢谢。 SERVER 这个词是大写的,我更正了我的问题以反映这一点。但这引起了我的注意,即在我的代码中我使用的是 REQUEST_URl(小写 L)而不是 REQUEST_URI(大写 i)。我从互联网上复制粘贴了这段代码。我纠正了错字,问题解决了。

标签: php .htaccess


【解决方案1】:

如果您想使用超全局变量,请使用大写字母。例如,如果你真的想返回 FULL 地址,你可以这样做:

$real_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

【讨论】:

    猜你喜欢
    • 2011-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-22
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    • 1970-01-01
    相关资源
    最近更新 更多