I'm using a index system to say:
On index i use:
<?php core::doPage(); ?>
Core code is:
<?php
class core
{
public static function doPage()
{
if(!isset($_GET["page"]) || empty($_GET) || !is_string($_GET["page"]))
{
if(!include_once('./_pages/index.php')) die("404 - File not found.");
}
else
{
$_GET["page"] = substr($_GET["page"], 0, -4);
$pages = array_map(function($x) { return str_replace(".php", "", basename($x)); }, glob("./pages/*.php"));
if(in_array($_GET["page"], $pages))
{
if(!include_once("./_pages/{$_GET["page"]}.php")) die("404 - File not found.");
}
else
if(!include_once('./_pages/404.php')) die("404 - File not found.");
}
}
}
?>
Any tweak suggestions or is this code fairly secure? Not exploitable?
pages
and_pages
that contain files with the same name? If so you'd better give'em a proper name (at least one of them), because it looks like backup. \$\endgroup\$