Hello,
Today I will be showing you a very basic way of loading all your pages through "index.php", rather than having to make a separate file for each page with the same template, includes, etc.
Today I will be showing you a very basic way of loading all your pages through "index.php", rather than having to make a separate file for each page with the same template, includes, etc.
PHP:
<?php
// here you could include the header of your site
// require_once 'skin/header.php';
/* CONFIG */
$path = 'path/to/pages/'; // path to the folder where you store pages
$default_page = 'home'; // if no page is set, this will be included
$default_404_page = '404'; // if the page does not exist, this will be included
/* SLAVE */
if(empty($_GET['page'])) { // check if you have set the page in the URL
$page = $default_page; //set the default page set in the config since no page was set in the URL
}else{
// the code below checks if the page contains only letters, numbers, underscores and/or dashes
// it also checks if the file exists
$page = (preg_match('/[^a-zA-Z0-9\ _-]/', $_GET['page']) || !file_exists($path . $_GET['page'] . '.php') ? $default_404_page : $_GET['page']);
}
// includes the page correct page
require_once $path . $page . '.php';
// here you could include the footer of your site
// require_once 'skin/footer.php';