Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Share common HTML code among different HTML files?

Reply
Thread Tools

Share common HTML code among different HTML files?

 
 
MK
Guest
Posts: n/a
 
      05-14-2005
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


 
Reply With Quote
 
 
 
 
Beauregard T. Shagnasty
Guest
Posts: n/a
 
      05-14-2005
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.
 
Reply With Quote
 
 
 
 
noSpAm0000
Guest
Posts: n/a
 
      05-15-2005
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)
 
Reply With Quote
 
noSpAm0000
Guest
Posts: n/a
 
      05-15-2005
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.
 
Reply With Quote
 
David Dorward
Guest
Posts: n/a
 
      05-15-2005
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
 
Reply With Quote
 
noSpAm0000
Guest
Posts: n/a
 
      05-15-2005
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 ...

 
Reply With Quote
 
noSpAm0000
Guest
Posts: n/a
 
      05-15-2005
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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
How to share common code among pages in asp.net 2.0 just_life ASP .Net 0 08-01-2007 05:31 PM
Re: How to share vector among different processes? red floyd C++ 1 09-06-2003 11:20 AM
how to limit access to common objects shared among multiple threads K Gibbs C++ 1 07-03-2003 10:32 PM



Advertisments