2-variable Page Include
This include script is pretty much the same as all the other, but it has a few improvements. The most important
is that it supports the use of two variables. Using two variables will allow you to put your different sorts of
pages into separate directories to improve the tidyness :)
It ONLY allows includes from the two directories specified in the script, thus blocks any attempts to include
pages you don't want included (that would've been a major security risk).
FAQ
- What does it do?
- An include script like this one is based on the PHP function include(). It takes a page and practicly copies the sourcecode into the page that uses the include function. It's as simple as that.
- So what makes a script like this so special?
- It allows you to have only ONE page. In my case it's index.php. This makes it easier than ever to change the look of your website. You only have to change one single file. There is no page-specific content on this page. Only the menu, header, footer, etc. All the content is located in separate files in a separate folder. The include-script takes one of these content pages and "copies" it into the location of your include-script. Which content page it includes depends on the URL. Example: http://www.epleweb.com/index.php?page=main will include main.php into index.php. The location (path) of main.php is defined in the script.
Installation
- Open the page in which you want the script and copy the sourcecode from include.php to the location where you want the content pages included.
- Take a look at the lines in the top of the script - the configuration area. $dir1 is the path to the directory where the pages for the first variable is located. Default is "./inc". Remember: Only change the part after the = and remember to keep the quotation marks. Also do this with $dir2 - this is where the pages for the second variable is located. If you're not going to use the second variable just let it stay at it's default and ignore it.
- Change $mainpage to the page that will be included if none of the variables is defined in the URL.
- Now we need to tell the script which file extension the content-pages have. Set $fileext to the correct extension. Remember the ".".
- If the URL wants to include a non-existing file, we need give some sort of error message. Change $error404 to the error message you want the user to see.
- Change the word between [' and '] to what you want to have in the URL. If you change $cat1 to page, the URL will be www.dot.com/index.php?page=mypage. The page will be included from the directory you defined in $dir1. Do the same with $cat2 if you want to use that aswell.