?
Solved

Need a modification to this simple script.

Posted on 2003-12-01
2
Medium Priority
?
193 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 1000 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

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …
Suggested Courses

743 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