Solved

Need a modification to this simple script.

Posted on 2003-12-01
2
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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 dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

717 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