Reply to Re: sending variable to include file

Your name:

Reply:


Posted by Chung Leong on 08/18/06 05:48

vetchling wrote:
> 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");?>
>
> Then the header.php file contains this code:
> <?php
> $page = $_GET['page'];
> ?>
> <html><head><title><?$page?></title>
>
> I want $page to contain the string "Home" of course, but it ends up
> being nothing but an empty string.

[rant against using includes as functions]

Just wrap a function around the HTML then call it. Later on you'll find
that it gives you a lot of flexibility. So instead of a header.php and
footer.php, you have one file, interface.php:

<?php function printHeader($page) { ?>
<html><head><title><? echo htmlspecialchars($page); ?></title>
<? } ?>

<?php function printFooter() { ?>
</body></html>
<? } ?>

In the different pages, you'd include this file then call the functions
at the right places:

<?php

require_once("interface.php");

printHeader('Welcome');

/* ... */

printFooter();

?>

[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

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