Solved

Need a modification to this simple script.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

910 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

21 Experts available now in Live!

Get 1:1 Help Now