|
Posted by Geoff Muldoon on 08/18/06 05:42
In article <1155873472.662698.276320@i42g2000cwa.googlegroups.com>,
vetchling@gmail.com says...
> Hi, I'm pretty new to php but I've been working on a site and have a
> problem I can't fix, though it's probably pretty simple.
>
> Basically I have an index.php file that includes a header.php file. I
> attempt to pass a variable to it as follows:
> <?include("header.php?page=Home");?>
Write your header (and footer if so warranted, example included) as a
function which returns the header text with the variable embedded in it,
and pass the variable to the function.
# header_footer_functions.php
<?php
function print_header($this_page) {
$text = '<html><head><title>'.$this_page.'</title></head>';
return $text;
}
function print_footer($author, $dept) {
$text = '<div>Author: .'$author.'<br />Dept: '.$dept.'</div></html>';
return $text;
}
?>
# home_page.php
<?php
include_once('header_footer_functions.php')
echo print_header('home');
?>
... rest of home page
<?php
echo print_footer('Slave Driver', 'Head Office');
?>
# some_other_page.php
<?php
include_once('header_footer_functions.php')
echo print_header('some other page');
?>
... rest of some other page
<?php
echo print_footer('Underpaid', 'Underlings');
?>
Geoff M
Navigation:
[Reply to this message]
|