I am searching for a kind of dynamic template engine which I want to built by the url. So if my url is like localhost/root/this/is/the/path/to/signup.php the php code should watch for the file signup.php in the directory this/is/the/path/to/
For this time I am using arrays of the url like the following code shows:
$url = isset($_GET['url']) ? $_GET['url'] : null;
$url = rtrim($url, '/');
$url = explode('/', $url);
if (empty($url[0])) {
$url[0] = "path/startpage.php";
}
if (isset($url[2])) {
require "path/error.php";
} else if (isset($url[1])) {
$file1 = 'path/' .$url[0].'/'.$url[1].'/'.$url[1].'.php';
if (file_exists($file1)) {
require $file1;
} else {
require "error.php";
}
} else if (isset($url[0])) {
$file0 = 'path/'.$url[0].'/'.$url[0].'.php';
if (file_exists($file0)) {
require $file0;
} else {
require "path/error.php";
}
}
But with this script I have to do this for every case and this is not so nice. I want to have a solution where the code is looking for the whole url, goes to the directory and require an error or the file, if it exists.
Could you help me please?