【发布时间】:2014-12-25 22:13:30
【问题描述】:
我想确保我的页面被包含在工作索引页面中。我想知道什么是确保我的页面被包含而不是自己呈现的正确方法?
现在我正在检查是否至少有 2 个包含的文件,但我不确定我是否会这样做。 包括('config/config.inc.php');
$cms = new cms();
if(($_SERVER['REQUEST_METHOD'] === 'GET' || $_SERVER['REQUEST_METHOD'] === 'POST') && !empty($_GET['page'])) {
include($cms->GetTheme() . "/head.php");
$cms->IncludeModule($_GET['page']); <- actual page being included
include($cms->GetTheme() . "/foot.php");
} // end (GET || POST) && GET
else { // just index.php
include($cms->GetTheme() . "/head.php");
foreach($cms->GetModuleList() as $module) {
echo " <a href=\"index.php?page=$module\"> $module </a><br />";
}
include($cms->GetTheme() . "/foot.php");
} // end ELSE
包含的页面以及我如何检查它是否包含
<?php
$module_name = 'Log out user';
$module_directory = 'admin';
$this->SetTitle($module_name); // setting page title
if(count(get_required_files()) < 2) {
header('Location: index.php');
}
else {
if(isset($_SESSION['user'])) {
$this->DestroyUser();
echo "You have been logged out! Please navigate to the <a href=\"index.php?page=login\">Login Page</a>.";
}
else {
header('Location: index.php?page=login');
}
}
?>
【问题讨论】:
-
如果您将要包含的文件移出网络根目录,您就会知道它们永远不会被自己请求。