PHP Include File :
PHP Include Files are PHP files that contain any HTML or
display on an HTML document. There are various reasons for displaying HTML, with PHP include
statements, that will make your programming experiences much easier. The first is for
maintaining interoperable content like headers and footers
that are reused on a multitude of pages. Lets say your website has 50 pages with the same
header menu or footer. If for some reason you want to make a change to your code, it becomes
a laborious task to manually make the changes to all 50 pages. With a PHP file you can write
the code once and save it as a PHP file, and then place a calling statement,
to the PHP file, on every page. So when you make a change to the PHP file all your pages will
display the same code.
A second reason might be to hide any valuable code. Although, PHP files can be viewed from
any browser, you could at least eliminate any inexperianced viewers from seeing your code
in your HTML document. There are ways to completely hide your code with Server Side Includes
but that process is beyond the scope of this article.
PHP File :
The process is quite simple, you create a PHP file and include the actual HTML
or Javscript code, you want to maintain, into the PHP file. For example:
The above code represents an HTML menu. The <?php and ?> tags
are PHP beginning and ending tags that constitute a PHP file.
//Header Menu from an HTML page.
echo '<tr><td colspan="2">';
echo '<a href="index.html">Home |</a>';
echo '<a href="PopUps.html">PopUps |</a>';
echo '<a href="htmlJvscript.html">HTMLCode |</a>';
echo '<a href="BanRot.html">BanRot |</a>';
echo '<a href="SlidePres.html">SlidePres |</a>';
echo '<a href="AdvjvScript.html">JScripts |</a>';
echo '<a href="eBookTempl.html">eBookTempl |</a>';
echo '<a href="Scrollers.html">Scrollers |</a>';
echo '<a href="Menues.html">Menus</a>';
The "echo" statement a PHP command tells the server to display
the text and or code within the single quotes. It acts just like the
command to each line, to display the code on your HTML pages.
Then save the file to something like "Menu.php" and upload the file to your website directory.
Calling The PHP File :
In each of your HTML pages, you must place a calling statement to the PHP file that includes
The above statement must be placed, on every page, where you want the code to display.
Prity simple ah, accept there is one complication. To use the calling statement and
the PHP file "Menu.php" as is you would have to change all of your html documents to a .php
extension. This could cause a lot of problems when you consider any of your web pages
and their search engine positions which would be changed by the .php extension changes. So to
avoid making vast extension changes and possibly destroying any search engine positioning,
you have to add two simple statements to an .htaccess file.
AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
These two statements simply expand the PHP mime type to accept .html or
.htm extensions. So to make the .htaccess file, you open any text editor like
notepad place the two above statements and save the file as ".htaccess" and
your done and you just saved yourself a ton of work.
Otherwise, to use the the "Menu.php" file and the
<?php include( statement as is you would have to change each and every page to a .php
extension and I don't think you would want to do that.
It might be helpful for displaying some ad type scripts. However, you can also get the same affects
using .js files.