php中的变量包括

时间:2017-11-01 20:49:55

标签: php include

你好,所以我无法让我的网站url variab使用包含这样$IN_LIONIMAGES['siteurl'];它将不起作用所以标题,导航和放大器页脚不会显示,因为它在包含。我做错了什么。所以不好解释。

P.S只要我在其他PHP标签之外,它就会显示<?php echo $IN_LIONIMAGES['siteurl']; ?>。那么这是否意味着你可以在其他PHP标签中使用PHP标签?如果是这样的话,我想做什么呢?

的index.php

<?php
$IN_LIONIMAGES = include('config.php');
?>

<?php include_once $IN_LIONIMAGES['siteurl'] .'/inc/header.inc.php'; ?>
<?php include_once $IN_LIONIMAGES['siteurl'] .'/inc/nav.inc.php'; ?>

<body>


    <section class="hero">
        <div class="background-image" style="background-image: url(<?php echo URLpath; ?>/theme/<?php echo THEME; ?>/img/hero.jpg);"></div>
        <h1>Welcome!</h1>
        <h3></h3>
        <a href="new.php" class="btn">Upload a Image</a>
    </section>


<?php include_once $IN_LIONIMAGES['siteurl'] .'/inc/footer.inc.php'; ?>

的config.php

    <?php
return [
    'siteurl' => 'http://sitename.com/',
];
?>

error_log中

[01-Nov-2017 21:13:39 UTC] PHP Warning:  include_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/lionimag/public_html/demo/index.php on line 15
[01-Nov-2017 21:13:39 UTC] PHP Warning:  include_once(http://lionimages.dnt5.com/demo/inc/header.inc.php): failed to open stream: no suitable wrapper could be found in /home/lionimag/public_html/demo/index.php on line 15
[01-Nov-2017 21:13:39 UTC] PHP Warning:  include_once(): Failed opening 'http://lionimages.dnt5.com/demo/inc/header.inc.php' for inclusion (include_path='.:/opt/cpanel/ea-php70/root/usr/share/pear') in /home/lionimag/public_html/demo/index.php on line 15
[01-Nov-2017 21:13:39 UTC] PHP Warning:  include_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/lionimag/public_html/demo/index.php on line 16
[01-Nov-2017 21:13:39 UTC] PHP Warning:  include_once(http://lionimages.dnt5.com/demo/inc/nav.inc.php): failed to open stream: no suitable wrapper could be found in /home/lionimag/public_html/demo/index.php on line 16
[01-Nov-2017 21:13:39 UTC] PHP Warning:  include_once(): Failed opening 'http://lionimages.dnt5.com/demo/inc/nav.inc.php' for inclusion (include_path='.:/opt/cpanel/ea-php70/root/usr/share/pear') in /home/lionimag/public_html/demo/index.php on line 16
[01-Nov-2017 21:13:39 UTC] PHP Warning:  include_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/lionimag/public_html/demo/index.php on line 29
[01-Nov-2017 21:13:39 UTC] PHP Warning:  include_once(http://lionimages.dnt5.com/demo/inc/footer.inc.php): failed to open stream: no suitable wrapper could be found in /home/lionimag/public_html/demo/index.php on line 29
[01-Nov-2017 21:13:39 UTC] PHP Warning:  include_once(): Failed opening 'http://lionimages.dnt5.com/demo/inc/footer.inc.php' for inclusion (include_path='.:/opt/cpanel/ea-php70/root/usr/share/pear') in /home/lionimag/public_html/demo/index.php on line 29

1 个答案:

答案 0 :(得分:0)

我想你想说:

$IN_LIONIMAGES = Array('siteurl' => 'http://sitename.com/');

然后它应该按预期工作。如果您愿意,可以将它放在config.php文件中