I want to include page in page like index.php?page= php echo GET
Because I need security in first place I would like to know how to make the follow code better and secure but I do not know how. The pages will be stored only in a special folder /pages/ with only pages.
The problem is that index.php uses the same metatags so it is not SEO friendly. How can I change page title and keywords using the follow code in index.php?page=
<?php
$unsafe = $_GET['pagename'];
$page = preg_replace('/[^A-Za-z0-9\-]/', '', $unsafe);
if (empty($page)){
include('pages/default.php');
}
$pages = array('default', 'pageone', 'pagetwo', 'another', 'last');
if (isset($pages[$page])) {
include('pages/' . $page . '.php');
} else {
include('pages/error-404.php');
}
?>
EDIT
I found a code that maybe can help with title and metatags. But still need help improving the security. Do you think the follow code I found may help?
<?php
function do_html_head($title,$keywords,$description)
{
// print an HTML head
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title><?php echo $title;?></title>
<META NAME="keywords" CONTENT="<?php echo $keywords?>">
<META NAME="description" CONTENT="<?php echo $description?>">
}
And then I apply it on the page where I need it like:
<?php
do_html_head('title text','keywords text','description text');
?>