Reply to Re: sending variable to include file

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация