【问题标题】:Browser variable not working on include?浏览器变量不适用于包含?
【发布时间】:2011-11-08 13:16:47
【问题描述】:

好的,所以我有一个代码,上面写着

if (!$num_users || $num_users !== 1 ) {
include_once('../assets/scripts/error.php?error=404');
exit();
}

它似乎不起作用,我收到错误

打开流失败:没有这样的文件或目录

但如果我将包含行更改为

include_once('../assets/scripts/error.php');

它有效。我需要在末尾加上?error=404 来告诉页面回显出那种类型的错误消息。任何帮助将不胜感激!

【问题讨论】:

    标签: php variables browser include


    【解决方案1】:

    事情确实不是这样的。 ?error=404 是在解析 PHP 代码时将通过 HTTP 服务器传递的参数。 include 实际上只是获取命名文件的内容并将它们插入到当前文件中。您可以在包含之前设置一个变量 $error,然后您可以在包含的文件中访问它。

    【讨论】:

      【解决方案2】:
      if (!$num_users || $num_users !== 1 ) {
          $error_type = 404;
          include_once('../assets/scripts/error.php');
          exit();
      }
      

      然后在error.php中,如果定义了变量$error_type就使用

      【讨论】:

        猜你喜欢
        • 2015-09-29
        • 1970-01-01
        • 2020-02-22
        • 1970-01-01
        • 2023-03-13
        • 1970-01-01
        • 1970-01-01
        • 2017-10-25
        相关资源
        最近更新 更多