【问题标题】:error using include_once with a php variable [closed]将 include_once 与 php 变量一起使用时出错 [关闭]
【发布时间】:2011-11-07 08:11:10
【问题描述】:
//$GLOBAL_includesPath = "http://localhost/smthing/";

    <?
       include_once $GLOBAL_includesPath.'global_menu.php';
    ?>

错误:

警告:include_once() [function.include-once]: http:// 包装器是 在服务器配置中通过 allow_url_include=0 禁用 C:\xampp\htdocs\smthing\includes\page_header.php 在第 39 行

警告: include_once(http://localhost/sthing/includes/global_menu.php) [function.include-once]:无法打开流:没有合适的包装器 可以在 C:\xampp\htdocs\smthing\includes\page_header.php 上找到 第 39 行

警告:include_once() [function.include]:打开失败 'http://localhost/smthing/includes/global_menu.php' 用于包含 (include_path='.;C:\xampp\php\PEAR') 在 C:\xampp\htdocs\smthing\includes\page_header.php 在第 39 行

【问题讨论】:

    标签: php


    【解决方案1】:

    相信我,您不想从 URL 中包含

    • 只要不是本地主机,就会有巨大的安全风险
    • 包含远程 PHP 文件将包含其输出; PHP 代码本身将在远程服务器上执行
    • 如果要输出,请使用 curl 或 file_get_contents()

    如果你不在乎,只想让它工作(糟糕!),错误告诉你所有你需要的:在你的 php.ini 中启用allow_url_include

    否则,使用include_once('path/to/your/file/global_menu.php');

    【讨论】:

      【解决方案2】:

      包含 HTTP url 意义不大。您确定要以这种方式包含您的文件吗?

      试试这个

      include_once $_SERVER['DOCUMENT_ROOT'].'/smithing/global_menu.php';
      

      【讨论】:

      • 感谢您的回答。但似乎不适合我。只是好奇,为什么我不能这样做 $GLOBAL_includesPath.'global_menu.php' (我的 $GLOBAL_includesPath 是 http 还是文件目录)
      • 为什么?你可以,只要 $GLOBAL_includesPath 指向一个本地文件。我使用 DOCUMENT_ROOT 只是因为我不知道文档根目录的路径是什么,而这个变量通常包含它。
      猜你喜欢
      • 2021-08-19
      • 2018-11-26
      • 1970-01-01
      • 1970-01-01
      • 2018-10-29
      • 1970-01-01
      • 1970-01-01
      • 2010-10-27
      • 1970-01-01
      相关资源
      最近更新 更多