dougui2254 2015-03-08 21:13
浏览 36

PHP包括来自GET和页面标题的页面

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');
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用