Forum Moderators: coopster

Message Too Old, No Replies

Change One Include on a Page with Several Using a Variable in the URL?

Change one include on a page based on a variable in the URL of that page.

         

clearpixel

6:33 am on Feb 18, 2007 (gmt 0)

10+ Year Member



I've posted some similar threads before with similar themese, but now I would like to be able to change one include on a page based on a variable in the URL of that page. I am trying to create on master page that calls all of the other components of the page (navbar, body area, footer, etc.) with includes. I want to have all of the links in the navbar contain a variable so that when that url is clicked the actual page doesn't change but the body area contains a different page based on an altered include. Does this make sense?

supermanjnk

6:45 am on Feb 18, 2007 (gmt 0)

10+ Year Member



you could do something like this

<?
if (isset($_GET["page"])) {
include($_GET["page"].'.php');
} else {
include ('mainpage.php');
}
?>

clearpixel

5:05 pm on Feb 19, 2007 (gmt 0)

10+ Year Member



Thanks! Just confirming that I would drop that code where I would want the included page to appear (e.g., the table cell) and the variable would be "page=abc" (looks like the code adds the .php extension to it?). Judging by the code if a variable isn't defined in the URL the code provides for a default page, correct?

supermanjnk

5:15 pm on Feb 19, 2007 (gmt 0)

10+ Year Member



That is correct, and obviously the php extension could be changed to whatever extension you needed.

clearpixel

5:29 pm on Feb 19, 2007 (gmt 0)

10+ Year Member



Thanks for the help! I just tested it and it all worked! I presume if I wanted to change mutliple includes I would just create different variable names for each and use the same code? I love PHP. :)

supermanjnk

12:19 pm on Feb 20, 2007 (gmt 0)

10+ Year Member



yes, you could do that.