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 9116839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:46:08+00:00 2026-06-17T04:46:08+00:00

I was writing a Site in php the last few weeks and always had

  • 0

I was writing a Site in php the last few weeks and always had a question in my mind. On my index.php I route all the templates file like this

    if(isset($_GET['search'])){
        include_once 'template/template.search.php';
    }
    elseif(isset($_GET['newsletter'])){
        include_once 'template/template.newsletter.php';
    }
    elseif(isset($_GET['product'])){
        include_once 'template/template.product.php';
    }
    elseif(isset($_GET['categories'])){
        include_once 'template/template.categorie.php';
    }
    elseif(isset($_GET['about'])){
        include_once 'template/template.about.php';
    }
    elseif(isset($_GET['sitemap'])){
        include_once 'template/template.sitemap.php';
    }
    else
    {   
        include_once 'template/template.index.php';     
    }

But for me it dosen’t look very clean. Is there a better possibility to handle a job like this ?

I already tried it like this, but didn’t worked out for me

    $i = 0 ;
    switch($i){
    case(isset($_GET['search'])):
        include_once 'template/template.search.php';
        break;
    default:
        include_once 'template/template.index.php'; 
        break;
}

Edit: Better writing in the title was a bit misleading some of you, so I’m searching for the best performance for sure.

  • 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-06-17T04:46:09+00:00Added an answer on June 17, 2026 at 4:46 am

    It’s not too much cleaner, but a switch is the best thing to use for this. Readability is about 15,000% better.

    switch(true) {
        case isset($_GET['search']):
            include_once 'template/template.search.php';
            break;
    
        // do more
    
        default:
            include_once 'template/template.index.php';
            break;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm biased towards writing fool-proof applications. For example with PHP site, I validate all
All, I am writing a little dynamic site in php, and am trying to
I'm working on a medium sized PHP site. I'm writing provider classes for my
i am writing a web site with a php on the server side. which
Ok, so I'm writing an application in PHP to check my sites if all
I am writing a php site using a mysql database for a class of
i have a PHP web site and i am writing some data to an
I wrote a small PHP script to edit the site news XML file. I
I am writing a site in PHP and I am noticing that the page
Some friends and I are writing a php site where we can log our

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.