HTACCESS Wrappers with PHP - That's all you've...
(Page 2 of 9 )
That's all you've got to do for the htaccess file. Save that as "htaccess.txt" -- we'll get back to it later.
For the actual wrapper, create a new text file with the standard tags, then assign your header and footer file names to variables called $header and $footer.
$header = "header.html";
$footer = "footer.html";
Redirecting a user to our script doesn't pass its contents to it, just the filename. If you call phpinfo() in your script and scroll to the bottom you can see all the server variables which give us the name. The element "REQUEST_URI" in $_SERVER gives us the relative path (/header/sample.html), but we want the full system path since we're going to be reading the actual file (/home/username/wwwroot/your.host/header/sample.html), which is "PATH_TRANSLATED".
$file = $_SERVER["PATH_TRANSLATED"];
The name of the file that just tried to be shown is now stored in the variable $file. Three simple things are left: output the header, output the actual file, then output the footer.
That's it. Here's the entire header.php file:
All that, in just nine lines of code. Download it here: http://www.jumpx.com/tutorials/wrapper/header.zip
More Web Development Articles
More By 359