Now, I include body.php into main.php by putting the following code into index.php: <?php include ("body.php"); ?> PHP: My problem is, how to include pages specified in the URL? For example, when I visit: index.php?dir=products, it will include products.php, when I visit index.php?dir=db/core, it will include core.php, which is put in the folder "db". And if nothing is specified in the URL, it will include home.php. How can I do that? Helping will be appreciated!
This should work <?php if (isset($_GET['dir']) && $_GET['dir'] != "") { $dir = $_GET['dir']; if (file_exists(''.$dir.'.php')) { @include (''.$dir.'.php'); } elseif (!file_exists(''.$dir.'.php')) { echo 'Page not found!'; } } else { @include ('home.php'); } ?> Code (markup): For the db/core thing to work, you'd probably have to assign another variable, something like "?dir=db&page=core". The script above will only check if products.php exists in the same folder, once a url like "?dir=products" is passed to it. You could maybe make a regex (regular expression) to find before and after the / in db/core with the folder & page name.
Or, an extremely simplified version of the above: if(isset($_GET['dir'])) { $dir = $_GET['dir']; include("$dir.php"); } Code (markup):