View Full Version : Headers and Footers

03-15-2003, 11:14 AM
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?


03-15-2003, 02:45 PM
prolly not the best way to do stuff, but it's how i do it

$title = "hello";
$text = "should see how this works now";

$d=fread($f, filesize("templates/index.tpl"));

$d = addslashes($d);

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

$d = stripslashes($d);

// template echoed
echo $d;

and index.tpl will be


03-15-2003, 10:30 PM
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?

03-23-2003, 11:55 PM
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!!

03-24-2003, 01:47 AM
You could try this. It's what I do. It's works well with all my files.

# 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

echo "<title>$title</title>";
Before you include the header file put $title = 'blah';
I hope this helps.

05-17-2003, 08:39 PM
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?

05-18-2003, 08:29 AM
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.