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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:48:12+00:00 2026-05-21T06:48:12+00:00

I am designing a Q & A website use php. Here is the directory

  • 0

I am designing a Q & A website use php. Here is the directory structure:

+include
  db.php
  user.php
  template.php
  ...
  question.php
+public
  +images
  +styles
.htaccess
index.php
...

I want to use index.php ‘s REQUEST_STRING to load a template.

For example: index.php?page=signin will load the function get_signin_template() in template.php. And will show the visitor a URL like http://example.com/signin/.

Here are my questions:

  1. How to load different templates in index.php (what should do in this file)?
  2. How to rewrite the url (using apache mod_rewrite)?
  • 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-21T06:48:13+00:00Added an answer on May 21, 2026 at 6:48 am

    Answer to Question 1

    $valid_templates = array('signin', 'logout', 'home');
    if(isset($_GET['page'])
       and in_array($_GET['page'], $valid_templates)) {
        $function_name = 'get_' . $_GET['page'] . '_template';
        $template = call_user_func($function_name);
    }
    

    See call_user_func() in the PHP manual and the in_array() function in the PHP manual.

    I think it is also worth mentioning that I would not do it this way myself. Mapping URLs directly to functions is an inflexible way of doing things.

    The reason I have added the $valid_templates array is to ensure the user doesn’t attempt to change the URL in an attempt to call a nonexistant function etc. You would need to add each page/template function to it.

    If you really like this way of working then I would recommend you check out Limonade as it uses a similar dispatch method as the one you are attempting to setup (the following example is from their official site):

    require_once 'vendors/limonade.php';
    dispatch('/', 'hello');
      function hello()
      {
          return 'Hello world!';
      }
    run();
    

    But is a little safer and easier to manage in my opinion. Plus all the “hard” plumbing work has been done and you can just focus on adding your pages.

    Another similar option is Slim, which looks like this:

    require 'Slim/Slim.php';
    Slim::init();
    Slim::get('/hello/:name', function ($name) {
        echo "Hello $name";
    });
    Slim::run();
    

    Example from their site.

    Answer to Question 2

    Something along these lines in your .htaccess file should work for your rewriting needs.

    RewriteEngine On
    RewriteBase /
    RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am designing a website (www.lathamcity.com) where I use the Unicode character &#x2022 to
I am designing & developing Reset Password form, where user provides username/email address so
I am designing a small website where user register and pay there monthly fee,
I'd been designing my website using Firefox 3.up & IE 8 as a reference.
So, I've started designing a TicTacToe GUI in Java & I'm stuck. Here's the
I'm designing sound applications with (sometimes HUGE) UI filled of UISlider & UISwitch. I'm
Im designing a website, and often I need to present information in a nice
while designing my user control, i encountered the following problem: i would like to
Im designing my school's website and I kind of want to do like a
I am designing a REST api for one of my applications & considering using

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.