another one is my site looks for mysql pages to load if it does not exist it looks for php pages, then static pages, if none are found it displays 404.
This will cover the static page part of the function.
Assuming you have header tags and a header page and a footer page to include for the links, title etc.
first thing then is to have a pointer, were the files are.
CODE
<?php
// no trailing slash
$mycontentdir = "/server/root/to/file/dir";
?>
OK, now to get the the file and open it in read mode.
originally i did this with an include, eather way will work.
CODE
<?php
if (is_file("$mycontentdir/$main_page")) {
$open = fopen("$mycontentdir/$main_page", "r");
$size = filesize("$mycontentdir/$main_page");
$content = fread($open, $size);
}
?>
now so that the file extension does not show, and to only allow viewing of extensions we choose. but will need to be above the open file function.
is important to keep everything in line properly. full code below.
CODE
<?php
$main_page = "" . $main_page . ".txt";
?>
OK, so now we need a way to view the opened content.
place it were you like, in a table etc.
CODE
<?php
print "$content ";
?>
so now we have a dynamic static page loader.
but, doh, it wont load anything till you click on a link?
OK, so if $main_page is empty, load this page. assuming you have a Home.txt page in the content dir.
placed at top of all the code.
CODE
<?php
if ($main_page == "") $main_page = "Home";
?>
so we built all the things needed, and now we put them together in proper order.
Also assuming again that you have header.txt and footer.txt in the content dir.
links, to load a page, ?main_page=Your Page-Name
CODE
<?php
$mycontentdir = "./content";
if ($main_page == "") $main_page = "Home";
@include("$mycontentdir/header.txt");
$main_page = "" . $main_page . ".txt";
if (is_file("$mycontentdir/$main_page")) {
$open = fopen("$mycontentdir/$main_page", "r");
$size = filesize("$mycontentdir/$main_page");
$content = fread($open, $size);
}
print "$content ";
@include("$mycontentdir/footer.txt");
?>
