如何正确检查是否包含页面?

时间:2014-10-30 01:05:30

标签: php include

我想确保我的网页被包含在工作索引页面中。我想知道什么是确保我的页面被包含而不是自己呈现的正确方法?

现在我正在检查是否至少有2个包含的文件,但我不确定它是否有行为。     包括('配置/ config.inc.php文件&#39);

$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'); 
        }
    }
?>

1 个答案:

答案 0 :(得分:0)

我不确定你是否在谈论这个:

include 'test.php';

如果是,那么做一个这样的简单测试:

<强> test.php的

$testVar = '1';

<强>的index.php

include 'test.php';
echo $testVar;

我不知道你正在使用什么库,所以我希望这个简单的例子能让你理解。

相关问题