Solved

Need a modification to this simple script.

Posted on 2003-12-01
2
190 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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 …

740 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