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

  • SEARCH
  • Home
  • 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 891917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:58:01+00:00 2026-05-15T13:58:01+00:00

Among the following include methods which is the best to practice and why? $page

  • 0

Among the following include methods which is the best to practice and why?

$page = $_GET['page'];

Method 1

$pages = array('home', 'blog', 'about');
if( in_array($page, $pages) )
{
    include($page.'.php');
{
else
{
   die('Nice Try.');
}

Method 2

if($page = 'home'){
include('home.php');
}else if($page = 'blog'){
include('blog.php');
}else if($page = 'about'){
include('about.php');
}

Method 3

if(str_replace("http://", "gth://", $page) == $page){
include_once $page;
}else{
       die('Nice Try.');
}

or any other solutions? I dont prefer method 1 and 2 as it always needs to be updated everytime i add a new page.

  • 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-15T13:58:02+00:00Added an answer on May 15, 2026 at 1:58 pm

    I believe that the first one is the best of the lot. You can try the second one, but it’s for the freshers. And the third one is a BIG NO, because any fresher hacker could hack your “if” condition, & more loopholes will start creeping in.

    As for your problem, on adding a new page to the array, every time a new page is created, for the first method, I have one solution:-
    Let’s say you’re putting all the new pages in one folder “abc”. Now just write one file code as the following, to read all the files / pages existing in that folder:-

    <?php
    $page = $_GET['page'];
    $pages = array();
    /**
     * If you are using all the pages existing in the current folder you are in,
     * then use the below variable as:-
     * $path = ".";
     */
    $path = 'abc/'; // Change the Path here, related to this Folder name
    $handle = opendir($path);
    while (($file = readdir($handle)) !== false) {
        $pages[] = $file;
    }
    closedir($handle);
    
    if( in_array($page, $pages) ) {
        include($page.'.php');
    }
    else {
        die('Nice Try.');
    }
    ?>
    

    So you see that the array is getting filled up dynamically, without the need to mention all the pages you create every time. And you are using the first method only. And keep the including pages in one separate folder, which you will need to include every time, in other main pages.

    Hope it helps.

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

Sidebar

Related Questions

I am working on converting a CVS repository that has the following symbols (among
My stuff is made with several components among which some are written in C.
I have an HTML page with a web form. Among other things, it includes
I think my problem is best described in code: #include <stdio.h> struct Foo; extern
Could anyone guide me as what is the difference among the following, 1) Visual
The problem I have is illustrated in the following code. #include <iostream> #define X
I was following along with the railscast regarding the restful_authentication plugin. He recommended running
I'm following along with this useful looking answer to my question . It seems
I'm learning C++ and writing little programs as I go along. The following is
Among other text and visual aids on a form submission, post-validation, I'm coloring my

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.