Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1056643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:44:40+00:00 2026-05-16T17:44:40+00:00

i’m trying to apply some module system on my web, using get and include,

  • 0

i’m trying to apply some module system on my web, using get and include, here’s some of my code
on my index.php

    $section = 'user';
    if(isset($_GET) && !empty($_GET) && $_GET !== ''){
        $module = $_GET['module'].".php";
        load_module($section, $module);
    }

load_module function

function load_module($section="", $module=""){
    include(SITE_ROOT.DS.$section.DS.'modules'.DS.$module);
}

*i have already define DS as DIRECTORY_SEPARATOR

and i stored few files inside modules folder, the file loads perfectly, my problem is that all the variable i declared on my included page fails to load, here’s my code on one of the included file

if($session->is_logged_in()){
    $user = User::find_by_id($session->user_id);
    $profile = $user->profile();
    $company = $user->compro();
    $logo = $user->logo();
}else{redirect_to('index.php');}

on my index.php i got this error

Notice: Undefined variable: session in C:\www\starpro\user\modules\edit_company.php on line 3 Fatal error: Call to a member function is_logged_in() on a non-object in C:\www\starpro\user\modules\edit_company.php on line 3 

and if i move those variables inside my index.php, i get this message

Notice: Undefined variable: company in C:\www\starpro\user\modules\edit_company.php on line 181  Notice: Trying to get property of non-object in C:\www\starpro\user\modules\edit_company.php on line 181

please some one help me, thank you in advance

Regards

======================================================================

i am using deceze’s answer

and modify my user’s class by adding a static function like this

public static function load_module($section="", $module="", $user_id=""){
$user = self::find_by_id($user_id);
    $profile = $user->profile();
    $company = $user->compro();
    $logo = $user->logo();
include(SITE_ROOT.DS.$section.DS.'modules'.DS.$module);
}

and then on my index i use this

if(isset($_GET) && !empty($_GET) && $_GET !== ''){
    $module = $_GET['module'].".php";
    User::load_module($section, $module, $user->id);
}else{

i got it working, but is this a bad practice ??
need advise

thanks much

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:44:41+00:00Added an answer on May 16, 2026 at 5:44 pm

    As has been stated, you are trying to include the code into the middle of the function, making the scope of the included page limited to that function.

    One solution would be to have a global array of files to include, then include them at the end of the script. Just add each file to the array, and at the end, loop through it and include them all.

    $includeFiles = array();
    
    ...
    
    function load_module($section="", $module=""){
        // include(SITE_ROOT.DS.$section.DS.'modules'.DS.$module);
        global $includeFiles;
        $location = SITE_ROOT.DS.$section.DS.'modules'.DS.$module;
        array_push($includeFiles, $location);
    }
    
    ...
    
    foreach( $inludeFiles as $location )
    {
        include_once($location);
        // using include_once so that if the file is added multiple times in the 
        // document, it only gets included once
    }
    

    It is also a massive security risk to include a file based on a parameter in the GET request. You should sanitize that input by either stripping or encoding all symbols which could be used to traverse to another directory and include code you don’t want included (so remove any slashes, etc.), or make a whitelist of includable files. If you had an array of sections and modules and their locations you could take an approach which would solve both problems:

    $modules = array(
        'section1'  => array(
                        'module1' => '/php/modules/module1.php',
                        'module2' => '/php/frameworks/foo/bar.php'
                        ),
        'section2'  => array(
                        'module1' => '/php/modules/baz.php',
                        'module2' => '/php/modules/quot.php'
                        )
        )
    }
    
    $modulesIncluded = array();
    
    ...
    
    function load_module($section="", $module="")
        global $modulesIncluded;
        array_push($modulesIncluded, $section => $module);
    }
    
    ...
    
    foreach( $modulesIncludes as $section => $module )
    {
        include_once($modules[$section][$module]);
    }
    

    Note: I have not tested any of this code, this is purely theoretical. I would not advise copying this, but using it as a jumping-off place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.