Share common HTML code among different HTML files?

M

MK

Dear friends,

I have many HTML files and they all have some common HTML code which is
basically bunch of tags which are in all the files. How can I put the common
code in one file and then share it in all the files? It is some thing like
following in all the HTML files which I have.

<HTML>
<HEAD> Common </HEAD>
<BODY>
..... Common code/tags
</BODY>
</HTML>

I want to do this so that I don't have to edit all the files if some common
code has changed. Your help is very much appreciated.

Regards,
MK
 
G

Guest

Dear friends,

I have many HTML files and they all have some common HTML code which is
basically bunch of tags which are in all the files. How can I put the common
code in one file and then share it in all the files? It is some thing like
following in all the HTML files which I have.

<HTML>
<HEAD> Common </HEAD>
<BODY>
.... Common code/tags
</BODY>
</HTML>

I want to do this so that I don't have to edit all the files if some common
code has changed. Your help is very much appreciated.

Regards,
MK

Try PHP. Its very simple code. If your server supports PHP, just include
this in your 'index.php' page wherever you want the changing content to go:

<?php
if (!isset($_GET['p'])) {
include("includes/default.php");
} else {
include("includes/" . $_GET['p'] . ".php");
}
?>


On your menu, or wherever the links go to load the different content, use
this code:

<a href="index.php?p=PageName">Link Text</a> (notice that the links do not
have a file extension. The php code adds .php to the link and grabs the
file from the includes directory).


All of your content should be saved in a directory called "includes" and
they should have the extension .php

If you have any questions, there are links to PHP tutorials on my website
at
http://s94621231.onlinehome.us
(getting a domain name soon).

So you have:

-index.php (your 'common code' with the php code mentioned above)
-includes (directory that contains the files you want to include)
 
G

Guest

//s94621231.onlinehome.us[/url]
(getting a domain name soon).

So you have:

-index.php (your 'common code' with the php code mentioned above)
-includes (directory that contains the files you want to include)

Sorry, I forgot to mention something -- your 'includes' directory should
have a file in it called default.php. That would be the initial content
that loads.
 
D

David Dorward

noSpAm0000 said:
Try PHP. Its very simple code.

Too simple.
<?php
if (!isset($_GET['p'])) {
include("includes/default.php");
} else {
include("includes/" . $_GET['p'] . ".php");
}
?>

If people include some "../" in their URL that will give access to any PHP
file on the computer. You need to make sure that doesn't happen. You also
need to check that the specified file exists before trying to include it.
Its safer to only allow access to specific files rather than any that the
user can guess the name of.
 
G

Guest

noSpAm0000 said:
Try PHP. Its very simple code.

Too simple.
<?php
if (!isset($_GET['p'])) {
include("includes/default.php");
} else {
include("includes/" . $_GET['p'] . ".php");
}
?>

If people include some "../" in their URL that will give access to any PHP
file on the computer. You need to make sure that doesn't happen. You also
need to check that the specified file exists before trying to include it.
Its safer to only allow access to specific files rather than any that the
user can guess the name of.

Thanks for pointing that out. I'm trying to figure out how to fix it now.
I got that from a PHP book ...
 
G

Guest

noSpAm0000 said:
Try PHP. Its very simple code.

Too simple.
<?php
if (!isset($_GET['p'])) {
include("includes/default.php");
} else {
include("includes/" . $_GET['p'] . ".php");
}
?>

If people include some "../" in their URL that will give access to any PHP
file on the computer. You need to make sure that doesn't happen. You also
need to check that the specified file exists before trying to include it.
Its safer to only allow access to specific files rather than any that the
user can guess the name of.

I found information here for whoever is interested in figuring out how to
make my bad PHP code example safer:
http://erics.seksibody.com/wiki/index.php/Tutorials:Includes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top