0

I want to make sure that my pages are being included working index page. I would like to know what would be correct way of assuring that my page is being included instead of rendered by itself?

Right now I'm checking if there are at least 2 included files, but I'm not sure I'd it's behavior. include('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

Included page and how I check is it's included

<?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'); 
        }
    }
?>
HelpNeeder
  • 6,383
  • 24
  • 91
  • 155
  • 1
    If you move the files to be included out of the web-root, you know they will never be requested by themselves. – jeroen Oct 30 '14 at 01:15

1 Answers1

0

I'm not sure if you're talking about this:

include 'test.php';

If yes, then do a simple test like this:

test.php

$testVar = '1';

index.php

include 'test.php';
echo $testVar;

I have no idea what library you're using, so i hope this simple example will allow you to understand.

FortMauris
  • 167
  • 7