Web Analytics Made Easy -
StatCounter Headers and Footers - CodingForum

Announcement

Collapse
No announcement yet.

Headers and Footers

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Headers and Footers

    I know that you can make headers and footers appear in documents using php, but how do you do this?
    Geoffrey Sneddon

  • #2
    PHP Code:

    include('header.php');

    # site content

    include('footer.php'); 
    Hope this helps
    Dave

    Comment


    • #3
      Originally posted by newmand2
      PHP Code:

      include('header.php');

      # site content

      include('footer.php'); 
      Hope this helps
      So would my page be like this
      PHP Code:
      <?php

      include('header.php');

      <
      p>There is no spoon</p>

      include(
      'footer.php');

      ?>
      And would header.php be like
      PHP Code:
      <?php

      <html>
      <
      head>
      <
      title>The Matrix</title>
      </
      head>
      <
      body>

      ?>
      Geoffrey Sneddon

      Comment


      • #4
        Found this... http://www.phphelp.com/article/3p1.php
        Geoffrey Sneddon

        Comment


        • #5
          Originally posted by Error 404
          So would my page be like this
          PHP Code:
          <?php

          include('header.php');

          <
          p>There is no spoon</p>

          include(
          'footer.php');

          ?>
          Uhm, no. You would have to replace
          PHP Code:
          <p>There is no spoon</p
          with
          PHP Code:
          echo('<p>There is no spoon</p>'); 
          And header.php SHOULD be like
          PHP Code:
          <?php
          echo('<html>');
          echo(
          '<head>');
          echo(
          '<title>The Matrix</title>');
          echo(
          '</head>');
          echo(
          '<body>');
          ?>
          There, basically you have to use echo() to use HTML.

          Hope that was helpful
          Dave

          Comment


          • #6
            Or the preferred way...

            PHP Code:
            <?php
            include("header.php");
            ?>
            <p>Blah blah blah</p>
            <?php
            include("footer.php");
            ?>
            Then in header and footer php, just use html only
            Code:
            <html>
            <head>
            etc etc
            Unless you want to use a bit of php in one of the files of course,

            Just makes things easier for you and you should really avoid using php just to echo html as much as you can.

            Comment


            • #7
              Nightfire's post was almost the way I did it, as I hadn't posted here yet.
              PHP Code:
              <?PHP
               $strPagetitle 
              'Welcome';
               require (
              'templates/header.php');
               require (
              'indexcontents.html');
               require (
              'templates/footer.php');

               
              ?>
              Geoffrey Sneddon

              Comment


              • #8
                Using php to echo html is pretty wateful. Part of the joy of using php is that you can intermix it in html. Instead of

                PHP Code:
                <?php
                include('header.php');
                echo 
                '<p>There is no spoon</p>';
                include(
                'footer.php');
                ?>
                Just use it where you need to :

                PHP Code:
                <?php include('header.php');?>
                <p>There is no spoon</p>
                <?php include('footer.php');?>
                It's a small difference in this example, but it makes much more sense in larger projects.

                HTH.

                Comment


                • #9
                  cool cool i learnt something here as well thanks all
                  Dave

                  Comment


                  • #10
                    On my site my header php file is:


                    PHP Code:
                    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                        "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd"
                    >
                    <
                    html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
                    <
                    head>
                    <
                    meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
                    <
                    title>The stubby web site</title>
                    <
                    meta name="description" content"Canadian Stubby Beer">
                    <
                    meta name="keywords" content="stubby beer bottle">
                    <
                    link rel="stylesheet" type="text/css" href="style.css">
                    </
                    head>
                    <
                    body
                    And my footer php file is:


                    PHP Code:
                    <hr></hr>
                    <center>
                    <?php
                        
                    echo '© 2001-';
                        echo 
                    date('Y');
                        echo 
                    ' Leonard Whistler';
                        echo 
                    '<br>email:  [email][email protected][/email]';
                    ?>
                    </center>
                    <hr></hr>
                    </body>
                    </html>
                    My navagation is also a separate php file. Using the include line makes building my web site very simple.


                    Leonard Whistler
                    http://www.stubby.ca
                    Last edited by Len Whistler; Feb 17, 2004, 01:56 PM.
                    Leonard Whistler

                    Comment

                    Working...
                    X