我忘记在这里提出这个问题: PHP Dynamic Include Help on Index.php?
如何制作这样的目录与php包含使用?例如。我想将page2重命名为规则,然后将rules.php文件放入名为/ rules /的文件夹中,所以现在它/rules/rules.php
结果,新网址会像index.php?category = rules& id = rules
这是新代码。
<?php
$page='';
if (isset($_GET['id'])){
$page = $_GET['id'];
}
$pageArray = array('index','css-pub1','page2','page3','page4','page5','page6');
$inArray = in_array($page, $pageArray);
if ($inArray == true) {
include(''. $page .'.php');
}
else {
include('main.php');
}
?>
答案 0 :(得分:0)
这应该这样做,但为了使其更安全,您必须在include
之前检查页面类别对的存在(也许您应该使用include_once
代替)
<?php
$page='';
if (isset($_GET['id'])){
$page = $_GET['id'];
}
if (isset($_GET['category'])){
$category = $_GET['category'];
}
$pageArray = array('index','css-pub1','page2','page3','page4','page5','page6');
$categoryArray = array('cat1','cat2','cat32');
$inArrayPage = in_array($page, $pageArray);
$inArrayCategory = in_array($category, $categoryArray);
if ($inArray && $inArrayCategory) {
include(''. $page .'/'.$category.'.php');
}
else {
include('main.php');
}
?>