1
votes

I'm having dubts on my website's structure. I've a config, lib and public folders in the root. config contains the config.php and other similiar, lib contains all php/html content (header, each page content, footer etc), while public folder contains all the subfolders for each page with the index.php inside. I did this for the url... Anyway, each of these index.php set their page name in a variable and call the config.php file and a module.php for the whole content. My problem is that since I have multi level subdirectory (news/sport/football) each index.php have different config path to call. The "deepest" files have many "../" before config/config.php.

Here's the index.php inside public/news/:

<?php  
require '../../config/config.php';


$MainPage = 'news';
$CurPage = 'news';


include_once(LIB_PATH. 'modules.php');  
?>

So, is there any way to get the absolute root dir so that the path is the same in all files? Also, is this structure correct?

2
Where is LIB_PATH defined, and what server are you using? - Cups
LIB_PATH is defined in config.php as well as other global defines. I work on it with EasyPhp on my pc and is temporarily in Altervista's servers. - JohnnyCau

2 Answers

0
votes

You should be able to call config.php from anywhere using an absolute path.

include "/config/config.php";

You cannot do this because PHP's ini_path does not include your directory.

Try reading this answer about where/how to add a directory to your php.ini path.

-1
votes
require $_SERVER['DOCUMENT_ROOT'].'/config/config.php';