1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How do you use PHP includes?

Discussion in 'Programming' started by justsomepoordude, Aug 11, 2006.

  1. #1
    I don't want to edit all my pages, just want one footer to be able to do that, please help me. Thanks.
     
    justsomepoordude, Aug 11, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php
    include("footer.php");
    ?>
    Code (markup):
    where footer.php is the file with your footer in it.
     
    mad4, Aug 11, 2006 IP
  3. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #3
    You do have to edit all your pages one last time to include the code that Mad4 provided.

    While you are doing that you might as well do a header.php also. :)
     
    Colbyt, Aug 11, 2006 IP
  4. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you have a good text editor such as textpad, you can do a search and replace across multiple files. Seach for </body> and replace it with <?php include 'footer.php'; ?></body> That can save you editing hundreds of files.
     
    exam, Aug 12, 2006 IP
  5. ziandra

    ziandra Well-Known Member

    Messages:
    142
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    138
    #5
    Every web page I write by hand looks like

    <?include $_SERVER['DOCUMENT_ROOT'] . "/template/preamble" ?>
    <TITLE>...</TITLE>
    ... other header stuff
    <?include $_SERVER['DOCUMENT_ROOT'] . "/template/top" ?>
    ... the real content
    <?include $_SERVER['DOCUMENT_ROOT'] . "/template/bottom" ?>

    where template/preamble contains

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>

    and template/top contains

    ...common header stuff
    </HEAD>
    <BODY>
    ... navbar stuff

    and template/bottom contains

    ...navbar termination stuff (i use tables, so sue me)
    ... copyright / ads if I have em
    </BODY>
    </HTML>

    Not as wonderful as smarty or one of the other templating languages but it works for me.
     
    ziandra, Aug 12, 2006 IP
  6. xeno

    xeno Peon

    Messages:
    788
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    0
    #6
    or use
    and code the file footer.inc
    to include the links you want
     
    xeno, Aug 13, 2006 IP
  7. smallbizstartupkit

    smallbizstartupkit Well-Known Member

    Messages:
    163
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #7
    I think it's best to use the <?php include("header.php"); ?> just in case your current host (or future host for that matter) does not have the .inc included as something that should be read as php in browsers. What happens is that someone can see the content of your file but with php you know for certain it is only rendered as html in the browser (other words they cannot see your coding). I don't think this is a big deal for something as simple as what you are proposing but I think it's just a good habit to have getting starting. best of luck to you.
     
    smallbizstartupkit, Aug 17, 2006 IP