[thelist] Including file using $page

Bob Meetin bobm at dottedi.biz
Sat Aug 30 19:03:19 CDT 2008

Rae wrote:
> I'm guessing this is a really easy question for everyone out there but 
> it seems to have me really stumped.  If I knew what words to use I could 
> google it but the combinations I'm using keep telling me the same old 
> thing.  I'd like to have my main index.php page, in the middle of that 
> is where the content will go based on the page the person is viewing. 
> Such as:
> <<Header, Menu, etc>>
> <?php include ("pages/$page.php"); ?>
> <<Footer, etc>>
> How do I define $page so that it pulls the appropriate page from within 
> my pages/ directory.  I've seen the outcome used in the url such as:
> http://www.somesite.com/index.php?page=somepage
> And is this the best way to achieve this?  Any help is appreciated!
> Rae
I don't know that this is the best option, but you could probably set a 
flag in your menu so that it points you there.

    <a href="index.php?page=about">About</a>

you may need to check using _POST or whatever that $page is being read, 
some variation of:

    <? if(!isset($_POST['submit'])) { $page=$_REQUEST['page']; } else { 
$page=$_POST['page']; } ?>

then in the page perhaps:

    if ( $page == "about" ) { include ("pages/$page.php"); }

Bob Meetin

Hook up with me on Twitter, Facebook, LinkedIn, Plaxo Pulse and Bebo
or catch my blog at www.dottedi.biz/blog.php

More information about the thelist mailing list