Possible to translate HTML into PHP?

Hehe glad to hear it, but you should not forget to remove the extensions in the $forbidden array.. I kinda did that wrong.

So it should be:

PHP:
//The pages that are not allowed to be reached by the visitor 
$forbidden = array('config', 'settings');

Oh right because you add them here..
PHP:
   include($section.'.php');
else
   include('index.php');

Well, either way I hope we solved his problem.
 
The following is simpler and more secure:
(Need to put the pages in /pages/ directory)

PHP:
<?php
$file = "pages/".preg_replace('#([^a-zA-Z0-9_-]+)#','',$_GET['p']).".php";
if(file_exists($file)) include($file);
else include("pages/404.php");
?>

?p=something will include pages/something.php (if it exists, otherwise pages/404.php).
 
Last edited:
If you went with repres3nt's method, you should whitelist the pages rather than blacklist them

otherwise, for example:
?p=../../.htpasswd(null-byte)

could output a directory's password, etc.
 
Last edited:
Back