Share common HTML code among different HTML files?

Discussion in 'HTML' started by MK, May 14, 2005.

  1. MK

    MK 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
     
    MK, May 14, 2005
    #1
    1. Advertising

  2. 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?Include_one_file_in_another

    --
    -bts
    -This space intentionally left blank.
     
    Beauregard T. Shagnasty, May 14, 2005
    #2
    1. Advertising

  3. MK

    noSpAm0000 Guest

    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, May 15, 2005
    #3
  4. MK

    noSpAm0000 Guest

    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.
     
    noSpAm0000, May 15, 2005
    #4
  5. 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
     
    David Dorward, May 15, 2005
    #5
  6. MK

    noSpAm0000 Guest

    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, May 15, 2005
    #6
  7. MK

    noSpAm0000 Guest

    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/index.php/Tutorials:Includes
     
    noSpAm0000, May 16, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. K Gibbs
    Replies:
    1
    Views:
    361
    MiniDisc_2k2
    Jul 3, 2003
  2. red floyd
    Replies:
    1
    Views:
    502
    Zhang Yan
    Sep 6, 2003
  3. just_life
    Replies:
    0
    Views:
    709
    just_life
    Aug 1, 2007
  4. Saraswati lakki
    Replies:
    0
    Views:
    1,428
    Saraswati lakki
    Jan 6, 2012
  5. John Reye
    Replies:
    28
    Views:
    1,420
    Tim Rentsch
    May 8, 2012
Loading...

Share This Page