hyperlinks and variables?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
silent assassin
Forum Newbie
Posts: 13
Joined: Mon Feb 27, 2006 6:53 pm

hyperlinks and variables?

Post 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.
User avatar
Fractal
Forum Commoner
Posts: 54
Joined: Tue Aug 16, 2005 1:28 pm

Post by Fractal »

Code: Select all

$page = $_GET['page'];
if (file_exists($page)) {
  include $page."php";
} else {
  include "index.php";
}
You mean somemthing like that?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

do note that including a user supplied page without a shread of validation checking is suicidal.
silent assassin
Forum Newbie
Posts: 13
Joined: Mon Feb 27, 2006 6:53 pm

Post 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
silent assassin
Forum Newbie
Posts: 13
Joined: Mon Feb 27, 2006 6:53 pm

Post 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
davidprogramer
Forum Commoner
Posts: 64
Joined: Mon Nov 28, 2005 6:11 pm

Post 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;
}
?>
silent assassin
Forum Newbie
Posts: 13
Joined: Mon Feb 27, 2006 6:53 pm

Post 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
silent assassin
Forum Newbie
Posts: 13
Joined: Mon Feb 27, 2006 6:53 pm

Post 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
Post Reply