PHP include page index.php?page=GET safety preg_replace
You are checking if a certain key exists in an array: isset($pages[$page]) but you define the $pages array without keys, so they default to numeric ones. A much better approach is to skip the preg_replace thing (it is useless anyway) and create a router array:


$router = array(
    'url' =&gt; 'pages/foobar.php',
    'default' =&gt; 'pages/default.php'
);


This array maps urls to your internal pages. Then you check or the requested page exists:

if (isset($router[$_GET['page']]) {
    include $router[$_GET['page'];
} else {
    include $router['default'];
}