Website structure 1
index.php - Index example
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My Website</title>
</head>
<body>
<?php
switch ($_GET["page"]) {
case "about":
include "pages/about.html";
break;
case "links":
include "pages/links.html";
break;
default "":
include "pages/index.html";
}
?>
</body>
</html>
index.php - is_file() example
<?php
$pages = array(
"about",
"articles",
"links"
);
if (in_array($_GET["page"], $pages) && is_file("pages/". $_GET["page"] .".html")) {
include "pages/". $_GET["page"] .".html";
} else {
include "pages/404.html";
}
?>
dynamic menu
<?php
// Only continue if we can open directory.
if ($handle = opendir("pages/")) {
print "<ul>\n";
// Loop through all files in pages/ directory.
while (false !== ($file = readdir($handle))) {
// Skip entries we don't want . and ..
if (ereg("^(\.|\.\.)", $file)) continue;
// Print menu entry
print "<li><a href=\"". $_SERVER["PHP_SELF"] ."?page=". $file ."\">". $file ."</a>\n";
}
print "</ul>\n";
// Close directory handler again
closedir($handle);
}
?>