Great usage of the Switch method,
however, I feel that people should be able to expand further, so we can include as many pages as we want .
Save this document as index.php
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Dynamic Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<table width="700" border="0" cellpadding="5" cellspacing="1" bgcolor="#eaeaea">
<tr bgcolor="#eaeaea">
<td height="100" colspan="2"> </td>
</tr>
<tr align="left" valign="top">
<td width="175" bgcolor="#f5f5f5"><h4>Navigation</h4>
<a href="index.php">Home</a><br />
<a href="index.php?page=contact">Contact</a><br />
<a href="index.php?page=links">Links</a><br />
<a href="index.php?page=downloads">Downloads</a><br />
<br />
</td>
<td bgcolor="#ffffff">
<h2>Welcome to My Site </h2>
<?php
$thefile = "includes/$page.php";
if (file_exists($thefile))
{
include("$thefile");
}
else
{
include("includes/start_content.php");
}
?></td>
</tr>
<tr align="center" bgcolor="#eaeaea">
<td height="30" colspan="2">© 2005 Yourname</td>
</tr>
</table>
</body>
</html>
Create a folder called "includes"
Next, save this as start_content.php in that folder:
(note we can stop people opening the page directly (good 4 security)
PHP Code:
<?
// keep people from accessing this page directly
if (eregi('start_content.php', $_SERVER['PHP_SELF'])) {
// go to index page
header('Location: ../index.php?page=start_content');
die();
}
?>
<p>Start Content Goes Here!</p>
Save this as contact.php
(This is a fully functioning contact form I have added to help out).
Just edit the content where appropriate.
PHP Code:
<?
// keep people from accessing this page directly
if (eregi('contact.php', $_SERVER['PHP_SELF'])) {
// go to index page
header('Location: ../main.php?page=contact');
die();
}
?>
<h4>ContactPage</h4>
Blah Blah
I hope this helps someone else out there. Just add more pages, using the headers as shown to prevent people opening the pages without going via the link "index.php?page=whatever"
Now you can see we can add more pages so easily, sinmce we are not stuck to predefined content blocks..!