Solved

Need a modification to this simple script.

Posted on 2003-12-01
2
186 Views
Last Modified: 2006-11-17
 I am using this script to include content into a template page.

function getContent() {
      if (empty($_GET['page'])) {
            $page = 'main';
      } else {
            $page = $_GET['page'];
      }

            $page .= '.php';

            if (false == is_file($page)) {
            $page = '404.php';
      }
      include($page); }

  Currently, if I call 'index.php' it returns the template file with content from 'main.php' included. If I call 'index.php?page=grapes' then the template is filled with a page about grapes - if it exists. If it doesn't (or I typed the URL wrong) then the template is filled with info from '404.php' It works like a charm, but I'd like to modify it a bit.

  I'd like it so that in the 'grapes' example, the template would fill with information from:

grapes/index.php

  Everytime I modify it to what I *think* will do the trick, it breaks the code or returns the 404 page. I'm sure this is a cake walk for those of you who know php, but I am stumped.

  Any takers?
0
Comment
Question by:TunaMaxx
2 Comments
 
LVL 13

Accepted Solution

by:
lozloz earned 250 total points
ID: 9852734
hi,

function getContent() {
     if (empty($_GET['page'])) {
          $page = 'main';
     } else {
          $page = $_GET['page'] . "/index";
     }

          $page .= '.php';

          if (false == is_file($page)) {
          $page = '404.php';
     }
     include($page);
}

loz
0
 

Author Comment

by:TunaMaxx
ID: 9852782
I knew that was gonna be easy...

Thanks!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now