【问题标题】:How to have more than one include on the same page in PHP如何在 PHP 的同一页面上包含多个内容
【发布时间】:2016-12-11 12:53:18
【问题描述】:

标题说明了一切,我一直在努力让它发挥作用,但它对我不起作用。它只是显示第一个包含。

<?php include 'config.php';  include 'https://theurl/that_the_header_is_on/header.php';  include '$header_url';  ?>

编辑:错误在这里:

[11-Dec-2016 03:26:13 Europe/Moscow] PHP 警告:include(): http:// wrapper 在服务器配置中被 allow_url_include=0 禁用 在第 4 行的 /home/myurlf/public_html/SimplePages/index.php [11-Dec-2016 03:26:13 Europe/Moscow] PHP 警告: 包括(myurl.fluctis.com/SimplePages/Default/1.0/header.php‌​): 无法打开流:找不到合适的包装器 /home/myurlf/public_html/SimplePages/index.php 第 4 行 [2016 年 12 月 11 日 03:26:13 Europe/Moscow] PHP 警告:include():打开失败

【问题讨论】:

  • 目前还不清楚您实际尝试做什么。当然,您可以使用由分号分隔的单独的 include 语句包含多个文件。您的代码包含不平衡的引号字符,并且似乎遗漏了一些分号...
  • 一般提示:在 http 服务器环境中编写 php 脚本时,您必须监控 hte http 服务器错误日志文件。否则这是一次盲目的飞行,你必须猜测发生了什么。从来都不是一个好主意。
  • 你能修复我的代码吗?我不知道我做错了什么,我在 config.php 中有一个名为 header_url 的变量我希望能够获取该变量并在包含变量中使用它,但它不允许多个包含。
  • 我在第一条评论中提到,目前尚不清楚您实际尝试做什么。那么您希望我们如何“修复”您的代码? “包含变量”是什么意思? “不允许”是什么意思?如前所述:当然多个include 语句是可能的,如果你使用有效的语法,正如我在第一条评论中所解释的那样。
  • 错误在这里:[11-Dec-2016 03:26:13 Europe/Moscow] PHP Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0在 /home/myurlf/public_html/SimplePages/index.php 第 4 行 [11-Dec-2016 03:26:13 Europe/Moscow] PHP 警告:包括(myurl.fluctis.com/SimplePages/Default/1.0/header.php):无法打开流:没有合适的包装器可以可以在第 4 行的 /home/myurlf/public_html/SimplePages/index.php [11-Dec-2016 03:26:13 Europe/Moscow] PHP 警告:include():打开失败

标签: php include


【解决方案1】:

这应该使代码运行。但是……

  <?php 
  include('config.php');        
  include('https://theurl/that_the_header_is_on/header.php');
  include($header_url);
?>

你想这样做吗? ..你的帖子有点混乱

<?php 
  include('config.php');        
  $header_url = 'Includes/header.php';
  include($header_url);
?>

【讨论】:

  • 我正在尝试从 config.php 中获取变量 $header_url 然后从 $header_url 给出的链接中获取包含中的标头
【解决方案2】:

试试这个。这是我目前使用的。

/**
 * Load all the class under RTlib\RTphp
 *
 * @return boolean False if error
 */
function RTphpLoad() {

    $lib = array();
    $lib[] = '/src/RTmysqli.php';
    $lib[] = '/src/RTpassword.php';
    $lib[] = '/src/RTslugify.php';
    $lib[] = '/src/RTutil.php';

    try {
        foreach ($lib as $class) {
            require_once dirname(__FILE__) . $class;
        }
        return true;
    }
    catch (Exception $ex) {
        trigger_error('RTphpLoad() Fail to load. ' . $ex->getMessage());
        return false;
    }
}

在另一个 php 文件中

require_once FILEROOT . 'RTlib/RTphp/load.php';

RTphpLoad();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    • 2013-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-13
    相关资源
    最近更新 更多