Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Mar 2003
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Headers and Footers

    I am a newbie to php, and thouht that maybe someone can point me in the right direction... (I tried looking for an answer on php.net, but didn't find what I was looking for.)

    Basically I want to have a php doc that loads a header and a footer. I suppose .tpl would be the best extension to have my header and footer in??

    And, within the header i want to include a cgi script like:
    $cgi_date = implode('',file('./cgi-bin/date.cgi'));

    and within the main php document, i want to be able to set the document's Page Title, which will show up in the browser's titlebar.

    If this is possible, can someone please show me how?

    Thanks
    JamesBond

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    prolly not the best way to do stuff, but it's how i do it

    PHP Code:
    <?
    $title 
    "hello";
    $text "should see how this works now";

    $f=fopen("templates/index.tpl","r");
    $d=fread($ffilesize("templates/index.tpl"));
    fclose($f);

    $d addslashes($d); 

    eval(
    "\$d = \"$d\";");

    $d stripslashes($d); 

    // template echoed
    echo $d;
    ?>
    and index.tpl will be
    Code:
    <html>
    <head>
    <title>$title</title>
    </head>
    <body>
    $text
    </body>
    </html>

  • #3
    New to the CF scene
    Join Date
    Mar 2003
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well i kind of wanted to have my body and such in each .php doc, and have the .php docs all read header.tpl and footer.tpl.

    Is that possible?

  • #4
    New to the CF scene
    Join Date
    Mar 2003
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone have an answer to my question?

    I guess this is hard to explain.

    My goal is to make .php docs that show the same header and the same footer throughout the site. Within the .php docs is the body of each page of my site, with the include of the header document and the footer document.

    Also within each .php document contains a $title variable that sets the header document's <title>$title</title>. Finally, within the header and footer document, there will be several cgi programs that I want executed.

    I appreciate all the help and feedback I can get!
    Thank you!!
    JamesBond

  • #5
    New Coder
    Join Date
    Feb 2003
    Location
    Warwick, RI
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could try this. It's what I do. It's works well with all my files.
    PHP Code:
    <?php
    include("header.php");
    # insert body here
    include ("footer.php");
    ?>
    You can use includes to make an easy template system.
    Make header and footer files and include them in all your php documents.
    In the header file put
    PHP Code:
    echo "<title>$title</title>"
    Before you include the header file put $title = 'blah';
    I hope this helps.
    Last edited by Eddyd84; 03-24-2003 at 12:52 AM.
    "Life is like a beautiful melody, only the lyrics are messed up."
    -anon

  • #6
    New to the CF scene
    Join Date
    Mar 2003
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    So, the whole include thing is working out for me. However, I am having a problem getting $title to post on pages that are not in the same directory as my header.php and my footer.php.

    Any page that is in a folder within the root dir, and has $title at the top of it, the header.php (located in root) does not read it. However, the pages (located in root) which also have $title, are being read, and the $title is being posted to what I set.

    Any suggestions?

  • #7
    New to the CF scene
    Join Date
    May 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think if you will get $title,you must used $_POST["title"] or $_GET["title"] or $_REQUEST["title"] if your php.ini set the register_globals = off.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •