Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   HTML (http://www.velocityreviews.com/forums/f31-html.html)
-   -   Share common HTML code among different HTML files? (http://www.velocityreviews.com/forums/t161788-share-common-html-code-among-different-html-files.html)

MK 05-14-2005 10:05 PM

Share common HTML code among different HTML files?
 
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



Beauregard T. Shagnasty 05-14-2005 10:15 PM

Re: Share common HTML code among different HTML files?
 
MK wrote:
> 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.


http://www.allmyfaqs.com/faq.pl?Incl...ile_in_another

--
-bts
-This space intentionally left blank.

noSpAm0000 05-15-2005 03:55 AM

Re: Share common HTML code among different HTML files?
 
On Sat, 14 May 2005 22:05:58 +0000, MK wrote:

> 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)

noSpAm0000 05-15-2005 04:04 AM

Re: Share common HTML code among different HTML files?
 
On Sat, 14 May 2005 23:55:05 -0400, noSpAm0000 wrote:
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)


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.

David Dorward 05-15-2005 09:50 AM

Re: Share common HTML code among different HTML files?
 
noSpAm0000 wrote:

> 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.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is

noSpAm0000 05-15-2005 09:42 PM

Re: Share common HTML code among different HTML files?
 
On Sun, 15 May 2005 10:50:44 +0100, David Dorward wrote:

> noSpAm0000 wrote:
>
>> 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 ...


noSpAm0000 05-15-2005 11:32 PM

Re: Share common HTML code among different HTML files?
 
On Sun, 15 May 2005 10:50:44 +0100, David Dorward wrote:

> noSpAm0000 wrote:
>
>> 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/inde...rials:Includes





All times are GMT. The time now is 05:31 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.