About PHP Includes
I was trying to use PHP include to containerize some repeating HTML code.
I made a test script to test out the concept. I knew that PHP is
working on the server because I'm using PHP to parse and send a contact
page on the same account. I had two files:
index.html
==========
<html>
<body>
<?php include ("header.inc"); ?>
<p>
Some text here, for example this would be the main content of my page
</p>
</body>
</html>
header.inc
==========
<html>
<body>
Some more text here
When I ran the index.html file I would get "Some text here..."
but not "Some more text here" and no PHP error. I
fiddled with changing double quotes to single and tried various
combinations of paths to the include file. None of this worked. What did work in the end was to rename the index.html file to
index.phtml.
By
the way, you can name the header.inc file with any extension, but most
professionals recomend naming it with php as an extension (header.php)
for security reasons. For some purposes (like using with a WYSIWYG HTML
editor) it may be better to use an extension of html - this too will
work!
The powerful thing about using PHP includes, is not just this little
example, but it is when you create a menu system using links to your
various pages in the "header.inc" file. when you have done this, you
can add a page to your web site by adding one more html file and making
one change to the "header.inc" file. If you do not use a system like
this, then changing the menu system is a pain becasue you need to got
into each file and paste in the new code.
This way you make the changes
in one place and just like magic your whole web site has the change.
This information brought to you as a service of http://yen9.com/ where you can host a small or medium sized site for $1 / per month. To check this out click on http://yen9.com/ .
Warning: include(/home/stevenf/adds/center-bottom.html) [function.include]: failed to open stream: No such file or directory in /home1/yenninco/public_html/sub/php-includes/index.phtml on line 151
Warning: include() [function.include]: Failed opening '/home/stevenf/adds/center-bottom.html' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php') in /home1/yenninco/public_html/sub/php-includes/index.phtml on line 151