PDA

View Full Version : Looking for basic header/footer script


YellowKard
Thu 25th Jan '01, 11:40pm
I'm trying to find a script / code to make a very simple script to get the job done. I'm recoding my site in php (majority of it will still just be html in a php file).

I want to either get a script or know how to include files inside a php script so I can make a standard header and footer thought my site.

Meaning.


anything.php contains

----------
header.bla (html or php)

html

footer.bla (html or php)
---------

I'm pretty sure what I'm trying to do is simple but I'm making it sound complicated. Thanks a lot to anyone who'd be so kind as in to assist me :)

JimF
Thu 25th Jan '01, 11:51pm
Make your header file, name it header.php (or whatever you want). Make your footer file, name it footer.php - or whatever you want.

In your page (index.php, for example), in the location you want your header, put this:


<?php include("header.php"); ?>


In the location you want to put your footer, put this:


<?php include("footer.php"); ?>


Now, upload header.php, footer.php, and index.php to your server, and run index.php from your browser. If it was done correctly, you should see the contents of both your header and your footer files, along with whatever content goes on the page.

HTH

-jim

YellowKard
Fri 26th Jan '01, 12:22am
Thanks a lot, thats exactly what I was needing to know, one question though, for the include do I need to use the system (absolute) or url (relitive) path?

Godin
Fri 26th Jan '01, 6:51am
relative path works fine :)

YellowKard
Fri 26th Jan '01, 8:53am
great

YellowKard
Fri 26th Jan '01, 7:54pm
Considering the future how could I call my varibles (such as the path for header.php and footer.php) from an external file

in other words say I got $header and $footer defined in another file, how could I define and call them so when I just use $header it prints the location of header.php in my output.

chrispadfield
Fri 26th Jan '01, 8:51pm
you would have to


require ("config.php");


where in config.php you have set

$footer = "/includes/footer.php";
$header = "/includes/header.php";

and then just do

include ($footer");

i think that works, if wrong someone will point it out.

YellowKard
Fri 26th Jan '01, 9:06pm
thanks, you guys help me figure out something I couldn't do with 4 php tuturials

Freddie Bingham
Fri 26th Jan '01, 9:36pm
this is what I use:


<?
chdir($DOCUMENT_ROOT . "/forums");
require("$DOCUMENT_ROOT/forums/global.php");
chdir($DOCUMENT_ROOT . "/include");

if (!file_exists("$file.html")) $file = "404";

$output="{htmldoctype}
<HTML>
<HEAD>
<TITLE>$bbtitle</title>
$headinclude
</head>
<body>
$header
<table border=\"0\" width=\"100%\" cellpadding=\"4\" cellspacing=\"1\">
<tr><td align=\"left\" width=\"100%\">
<img src=\"http://www.chins-n-quills.com/forums/images/closedfolder.gif\" border=0 width=14 height=11>
<b><FONT face=\"verdana,arial,helvetica\" size=\"2\"><a href=\"http://www.chins-n-quills.com/forums/index.php\">$bbtitle</A></font><
/b>
<img src=\"http://www.chins-n-quills.com/forums/images/closedfolder.gif\" border=0 width=14 height=11>
<b><FONT face=\"verdana,arial,helvetica\" size=\"2\">$file
</font></b>
</td></tr></table><br>";

$output .=
implode('',file("http://www.chins-n-quills.com/include/$file.html"));

$output .= "<br>$footer
</body>
</html>";

print dovars($output);
?>


That is called include.php and I call it like include.php?file=Privacy and it would load Privacy.html and place it inside my header/footer which maintains the look of my forum. The $footer and $header are supplied from global.php through the normal vbulletin routines. I use this so I can keep track of users on my site and display them on the forum index. When we get a chance to write who's online for vb2.1 than this can also be integrated into that to show where user's are outside your main forum.

YellowKard
Fri 26th Jan '01, 9:46pm
Very cool, I can see how to edit it and all but I was just curious about how you learned php, I'm wanting to end up being able to create my own scripts and not just edit others.

YellowKard
Fri 26th Jan '01, 9:48pm
Oh and one more thing, I'd like to comment how vB just resizes the reply that takes up more then the window width instead of the all the posts, unlike any other bulletin board I've seen.

YellowKard
Wed 31st Jan '01, 10:02pm
I need some help, I know there are some obvious problems but I don't know how I would make this setup work.

This is my file tree

|
|- beta/
|------ index.php
|------ config/
|------------ config.php
|------------ header.php
|------------ footer.php
|

index.php contains:

<?php
chdir($DOCUMENT_ROOT . "/beta/config");
require("$DOCUMENT_ROOT/beta/config/config.php");

// Page Settings

///////////////////
$title="This is a test";
$keywords="test,tester,testing";
$description="This is the description of a test";
///////////////////

include ("$header");
print "

This is a <b>test</b>.

";
include ("$footer");
?>

config.php contains:

<?php
chdir($DOCUMENT_ROOT . "/beta/config");
$header = "header.php";
$footer = "footer.php";
?>

header.php contains:

<HTML>
<HEAD>
<TITLE><? $title ?></TITLE>
<META name="description" content="<? $description ?>">
<META name="keywords" content="<? $keywords ?>">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">

and footer.php contains:

</BODY>
</HTML>


My server uses php 4 if that matters on how it should be coded.

YellowKard
Thu 1st Feb '01, 11:14pm
I swear I'll help others with the info I learn if someone helps me :)

chrispadfield
Thu 1st Feb '01, 11:22pm
first of you need to tell us what is going wrong.

I think the first problem is


("/config/config.php");


change it to


("config/config.php");


this is a path thing also i think this would work


("/beta/config/config.php");


but you may even have to do:

chdir($DOCUMENT_ROOT . "/beta/config");
require("$DOCUMENT_ROOT/beta/config/config.php");

not sure, try them, tell me error messages you get for each and i will try and help.

chrispadfield
Thu 1st Feb '01, 11:24pm
and it should be

include("$variable");

ie, both quotes, it was my mistake earlier one.

YellowKard
Fri 2nd Feb '01, 12:27am
Ok, first off, thank you guys for your time.

I updated the code to what I have it as now. I fixed the varibles by adding that first quote, I changed the directory path and had to use the chdir because it complained about being the the wrong folder. I also noticed I had an equal sign in my print statment before the quotes.

The only thing is it's not inserting my varibles into the called code, this is the html that is outputted to the browser when I load index.php

<HTML>
<HEAD>
<TITLE>$title</TITLE>
<META name="description" content="$description">
<META name="keywords" content="$keywords">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">

This is a <b>test</b>.

</BODY>
</HTML>

Also I've noticed some people use <? PHP HERE ?> to include php code and not <?php PHP HERE ?> is there a difference?

chrispadfield
Fri 2nd Feb '01, 12:41am
um swap:


include ("$header");


for


require("$header");


this may work but not 100% sure.

there is no difference in the php thing you asked about.

Mike Sullivan
Fri 2nd Feb '01, 12:57am
In practice, include and require perform the same function. The difference is when the file is added, but I'm not going to get into that.

<? is the "short open" tag. That's about it.

chrispadfield
Fri 2nd Feb '01, 9:12am
sorry i was being an idiot, no wonder it does not work:


<HTML>
<HEAD>
<TITLE>$title</TITLE>
<META name="description" content="$description">
<META name="keywords" content="$keywords">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">


needs to be in php code to work. At the moment this will do nothing. Either change to:


<?php
echo "<HTML>";
echo "<HEAD>";
echo "<TITLE>$title</TITLE>";
echo "<META name=\"description\" content=\"$description\">";
echo "<META name=\"keywords\" content=\"$keywords\">";
echo "</HEAD>";
echo "<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\" LINK=\"#0000FF\" VLINK=\"#800080\">";


or you can do the <? and ?> just around $title like

<TITLE><? $title ?></TITLE>

(advantage is then that you don't have to put the \ in front of all the " in the html code.

YellowKard
Fri 2nd Feb '01, 5:42pm
Alright, everything is working *except* its not using the varibles I set, such as in the html code it jsut says like

<META name="description" content="">
<META name="keywords" content="">


In other words, its just ignoring the <? $variblehere ?> that I put into the header and footer

I updated my codes in my ealier post

chrispadfield
Fri 2nd Feb '01, 8:25pm
i will test this on my home pc and try and get it to work, normally i do it the other way round, include files that contain variables as opposed to the text with the variables in the main script so not sure what is going on. Am away for the weekend so a day or two before i can work it out although someone else might be able to help.

YellowKard
Fri 2nd Feb '01, 8:30pm
Well im new to this as you can see, I'll take recommendations for how to do it, so I can easily customize things. Thanks for your time

YellowKard
Tue 6th Feb '01, 7:52pm
I hope you don't forget about me chrispadfield :)