2014-08-27 189 views
0

所有这些都包含在我的public_html文件夹内的文件夹中。头文件包含路径

/Public_Html 
    /folder 
     /css 
      -style.css 
     /includes 
      -shop.css 
      -header.php 
      -footer.php 
     /php 
     /js 
     /shop 
      -index.php 

     -index.php <-- homepage 
     -config.php 

里面我的config.php我已经

定义( 'ROOT_PATH', '' http://example.net/folder“);

我的header.php有这个顶部

<?php include '../config.php';?> 

的问题是,我只希望包括header.php文件中的配置文件,但要它的路径工作,它是在任何目录。所以,例如它可以在/shop中正常工作,但不能在文件夹的根索引文件中使用,因为config.php的路径不正确。

有什么建议吗?

+0

1. shop.css确实在包括如果你已经CSS目录? 2.使用绝对路径而不是相对路径并解决问题。 – Robert 2014-08-27 13:03:39

+0

@Robert因为它只包含在商店的index.php中。因此,它是一个包含和CSS路径写在每个页面上包含的header.php。 – ProEvilz 2014-08-27 13:10:40

回答

0

总是包含使用实时路径。

include realpath(__DIR__ . '/'. './config.php'); 
在config.php

包括这样

include realpath(__DIR__ . '/'. './includes/header.php'); 

如果没有文件PHP5.3

include realpath(dirname(__FILE__) . '/'. './includes/header.php'); 
+0

标题不包含在config.php中。 config.php包含在头文件中。 – ProEvilz 2014-08-27 13:09:32