Page 1 of 1

hyperlinks and variables?

Posted: Mon Feb 27, 2006 9:06 pm
by silent assassin
Feel like a complete novice on this one, I know a few other programming languages, but for some reason, I just realized I have no idea how to do this via php.

I have an index page, which consists of 6 parts, all includes. Includes are header.php, menu.php, submenu.php, body.php, bottommenu.php, and footer.php.

Now, currently, I have this for the body.php include...

Code: Select all

<?php
if($pageid != '')
{
	include($pageid);
}
else
{
	include("body.php");
}
?>
what I want to be able to do is have different hyperlinks that will enable me to change what page is included in the body, or, rather, more precisely ,change the variable $pageid on click and load the page with the new page in place.

And for some reason, for the life of me, I can't wrap my head around it.

Any suggestions guys? or for that matter, a better way of doing what I'm trying to do?

Thanks in advance, ciao.

Posted: Mon Feb 27, 2006 9:27 pm
by Fractal

Code: Select all

$page = $_GET['page'];
if (file_exists($page)) {
  include $page."php";
} else {
  include "index.php";
}
You mean somemthing like that?

Posted: Mon Feb 27, 2006 11:19 pm
by feyd
do note that including a user supplied page without a shread of validation checking is suicidal.

Posted: Tue Feb 28, 2006 12:38 am
by silent assassin
Fractal wrote:

Code: Select all

$page = $_GET['page'];
if (file_exists($page)) {
  include $page."php";
} else {
  include "index.php";
}
You mean somemthing like that?
Hmmm....not exactly, I was thinking more along the lines of having a link, lets say somewhere in the body, that on click, CHANGES whats IN the $page variable. Like lets say, initially, index.php includes body.php. After clicking on a link (say the link is to contact.php), I want the link to be able to change the $page variable so that $page = "contact.php".

Basically, I want hyperlinks to be able to change variables. I need the code for the hyperlinks I guess.

OR, I need a way to include files through another method, suggestions are welcome :)

Thanks again

Posted: Tue Feb 28, 2006 12:39 am
by silent assassin
feyd wrote:do note that including a user supplied page without a shread of validation checking is suicidal.
*nods* I agree, there will be sufficient validation, right now I'm a little more hung up on the theory, its still in developmental stages (obviously :) )

Thanks for the concern and your time

Ciao

Posted: Tue Feb 28, 2006 12:44 am
by davidprogramer
This?

Code: Select all

<?
$page = $_GET['page'];
switch($page){
case "file1":
  include ("header.php, menu.php, submenu.php, bottommenu.php, and footer.php");
  break;
case "file2":
  include ("body.php");
  break;
}
?>

Posted: Tue Feb 28, 2006 12:57 am
by silent assassin
hmm....again, no, not exactly. Here, let me explain.


typically, with this code....

Code: Select all

<?php
if($pageid != '')
{
   include($pageid);
}
else
{
   include("body.php");
}
?>
...body.php is typically loaded. Lets say there's a hyperlink in body.php that is supposed to load body2.php instead of body.php into the original index file.

My question is, what is the code for the HYPERLINK? And to be specific, I want the hyperlink to CHANGE $pageid variable.

here...my following post will have the examples

Posted: Tue Feb 28, 2006 1:03 am
by silent assassin
this is index.php

Code: Select all

<?php include("header.php"); ?>
<?php include("menu.php"); ?>
<?php include("submenu.php"); ?>

<?php
if($pageid != '')
{
   include($pageid);
}
else
{
   include("body.php");
}
?> 

<?php include("bottommenu.php"); ?>
<?php include("footer.php"); ?>


here's the code for body.php...

Code: Select all

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="50%" align="left" valign="top">Add Entry </td>
    <td width="50%" align="right" valign="top">Delete Entry </td>
  </tr>
  <tr>
    <td width="50%" align="left" valign="top">View Entry </td>
    <td width="50%" align="right" valign="top">&nbsp;</td>
  </tr>
</table>
Now, what I WANT to do is hyperlinkg "Add Entry", "Delete Entry", and "View Entry" so that they change the $pageid variable, and thus, they'll make the page load differently by inserting different pages into the include instead of using body.php.

Hope this helps :). Keep in mind, this is NOT supposed to be a form, just a link that subs in pages. If you have a better idea, I'd love to hear it as well, whether or not it means I'm including pages or not.

Thanks again guys