View Full Version : A simple page creator


Andrew Green
11-09-2005, 12:49 AM
With some comments ;)

What it does:

Pulls in the file "template.php" which has to have two functions
- showhead() = draws everything above the main body cell
- showfoot () = everything bellow

Draw the head (everything above the function)

then draw the body, in which 3 things can happen:
1) action=apagename it turns this into apagename.php, looks for the file and doesn't find it, prints a error message.

2) action=apagename it turns this into apagename.php, looks for the file and does find it. Sticks the contents of that file into the body.

3) pic=apicturename - displays the picture in the body , shows desc as a title and creates a "back" link based on action.

then draws the footer (everything below that)

Examples

index.php
-> loads main.php in the body

index.php?action=history
-> Loads history.php in the body (if it exists)

index.php?action=history&pic=myimage.jpg
-> Loads image/myimage.jpg into the body, creates a back button to history.php

index.php
<?php

require_once('template.php');
showhead();


if ($_GET['pic']!=""){
$image = $_GET['pic'];
$desc = $_GET['desc'];
$action = $_GET['action'];

if (!file_exists($image)){
echo "The image you are trying to access does not exist.";
}
else
{
echo "<h2>$desc</h2>
<p>
<img src='images/$image' alt='$desc'/>
</p>
<p>
<a class='inbody' href='index.php?action=$action'>Back</a>
</p>
";
}
}
else if ($_GET['action']!="")
{
$page = $_GET['action'];
$page = "$page.php";
if (!file_exists($page)){
echo "The Page you are trying to access does not exist.";
}
else {
require_once($page);
}
}

else {
$page="main.php";
require_once($page);
}


showfoot();

?>

BlueDragon1981
11-09-2005, 12:54 AM
I want to work with php...but haven't got the time to learn....at least not yet.

Andrew Green
11-09-2005, 01:04 AM
Learn xhtml and css first, once you start php cheating with graphical editors isn't as easy ;)