How to include a header

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mkyb14
Forum Newbie
Posts: 12
Joined: Sat May 28, 2005 7:46 pm

How to include a header

Post by mkyb14 »

ok i am making a website for a client and thus am looking for a simlier way of recalling the links and header part of the html page. does anyone have an example of how i can have the header part in php from a diff file and recall it with a simple code in the pages so that all i have to do to update every pages header/links is update that one file and the rest will do according with the php code? PLEASE this guy is driving me up the wall.

d11wtq | Watch your language!!!
thegreatone2176
Forum Contributor
Posts: 102
Joined: Sun Jul 11, 2004 1:27 pm

Post by thegreatone2176 »

very easy

look up include()

so you could stick everything in header.php then on every page include("header.php"); and then whne you want to edit you just edit that file

i think you posted in the wrong section but o well
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I edited your title. Reguardless of how urgent your problem is we treat it with just as much priority as yours. Please make futur titles more relevant. Thanks

Moved to PHP-Code.
mkyb14
Forum Newbie
Posts: 12
Joined: Sat May 28, 2005 7:46 pm

output a link table in php

Post by mkyb14 »

ok i'm looking to use php to output a table "html" for my links in php so that all i have to do is call

Code: Select all

include 'header.php';
With in the pages so i'm not recopying to everypage and modifying the links is simplier.

so i have done this so far.

Code: Select all

$header = ("");
echo $header;
my question is how do i format this in php so that it outputs correctly?
I don't need a full conversion but a few lines and i'll do the rest so that i know how to format html within php correctly. googling this has only gotten me some wierd or more complex versions of this. PLEASE HELLLLLP

<table width="700px" border="0" cellpadding="0px" cellspacing="0px" align="center">
<tr>
<td width="15%">&nbsp;</td>
<td class="center_table" width="700px">

<div id="title"><img src="images/title.png" width="700px" height="116px"></div>
<center>
<div class="menu" align="center">
<a href="#" target="_self" class="menu_left" onmouseover="style.backgroundColor='#cccccc';" onmouseout="style.backgroundColor='#f1f1f1'">Home</a>
<a href="bio.php" target="_self" class="menu_right" onmouseover="style.backgroundColor='#cccccc';" onmouseout="style.backgroundColor='#f1f1f1'">Biography</a>
<a href="resume.php" target="_self" class="menu_right" onmouseover="style.backgroundColor='#cccccc';" onmouseout="style.backgroundColor='#f1f1f1'">Resume</a>
<a href="pictures.php" target="_self" class="menu_right" onmouseover="style.backgroundColor='#cccccc';" onmouseout="style.backgroundColor='#f1f1f1'">Pictures</a>
<a href="projects.php" target="_self" class="menu_right" onmouseover="style.backgroundColor='#cccccc';" onmouseout="style.backgroundColor='#f1f1f1'">Projects</a>
<a href="links.php" target="_self" class="menu_right" onmouseover="style.backgroundColor='#cccccc';" onmouseout="style.backgroundColor='#f1f1f1'">Links</a>

</div>
</center>
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

I'm confused now. at first you wanted information about how to include a header that is a central location for html (links etc).

include(), require(), require_once etc. will work.

so now do you want information about how to create a string of html and then output it?

if so:

Code: Select all

$stuff = "<table width=\"700px\" border=\"0\" cellpadding=\"0px\" cellspacing=\"0px\" align=\"center\"> 
<tr> 
<td width=\"15%\">&nbsp;</td> 
<td class=\"center_table\" width=\"700px\">";
echo $stuff;
obviously using the scenario you first described, you'd want to include that (assuming it's going to be your header info) in the header.php file then include it with:

Code: Select all

require_once("header.php");
mkyb14
Forum Newbie
Posts: 12
Joined: Sat May 28, 2005 7:46 pm

php to output html

Post by mkyb14 »

ok i'll try to clarify.

I'm looking to take a section of html code which is my links and create a header.php. now within the header.php just have it setup so that in my other pages i can just call

Code: Select all

include 'index.php';
or your require function (which i dunno what that does).

ultimatly so that when i edit the links or add them in the future i'm only editing the header.php and not 8 pages of html to change the links to be the same for all the files.

.... does this make sense?
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post by Syranide »

haven't you just answered your own question?
include does what you want... unless I'm totally missing the point.
require btw is the same as include, but bails on error.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

first create your index.html page.

secondly anything that you want to include as a header on every page cut out and save as header.php

save your index.html page as index.php

on your index.php page at the top where your code you cut out was do..

Code: Select all

<?php
include ('header.php');
?>
//rest of your html code here.
you then should be able to do this for any other page.

just remember to save then as .php pages otherwise your include statement won't work.

I know simple example but it should get you going.
mkyb14
Forum Newbie
Posts: 12
Joined: Sat May 28, 2005 7:46 pm

answered

Post by mkyb14 »

yea i did answer it myself. plus you have to remove all the "" in the php file unless there is another way to seperate items such as multiple class's being called in php
original: class="header other"
php: class=header other <---doens't work for second class?
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Post by andylyon87 »

if you have include("header.php");
you don't actually you can search for the " and replace with /" and that cancels out all the "" in php but will display them in html so you can have a spaced class.
mkyb14
Forum Newbie
Posts: 12
Joined: Sat May 28, 2005 7:46 pm

doesn't output html correctly!

Post by mkyb14 »

your { /" } doens't output the html correctly as well as images etc. so then what do you use instead of {""} for html being outputed by php?
Post Reply