Forum Moderators: coopster
I'm unsure how to do this - I know it can be done, so I'm hoping someone here can help me.
I have a PHP based file (page1.php) In there I have a link to an include file that makes up the menu system of the page. No problem so far.
Also in there is another include file (header.inc or header.php I'm not sure which is best to use for this - I have tried both .inc and .php here and both produce the same result) that references the header information. These two include files are on all pages of the site - allowing me to easily change one file to reflect menu or header changes on all pages. Great so far no problem.
However. In the header.inc file is a page title. Each page that is to come up in the browser is to have a page title. For example page1.php has a page title of Page 1 in bold letters at the top of the page. This tells the viewer what page they are on. Likewise page2.php has a title of Page 2, etc. (This is in the page itself not at the top of the menu bar of the browser window)
This data is in the header.inc file. Therefore I need to dynamically change that section of the include file to reflect the current page.
So what I have in the page1.php is the following:
<html>
<head>
<title>Some sort of page title here</title>
<link rel="stylesheet" href="includes/style.css" type="text/css" />
<?
// Name of this page
$pgname = 'Put the page name here';
?>
</head>
<body bgcolor="#ffffff" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">
<?
include("includes/header.inc");
?>
...snip...
...snip...
<tr>
<td bgcolor="#FFFFFF" valign="top" height="40" width="19"><img src="images/layout/Trans.gif" width="1" height="1" border="0" alt></td>
<td valign="middle" align="center" nowrap class="bah" height="40"><? echo '.$pgname.';?></td>
<td valign="top" height="40" align="right" nowrap colspan="2"> <a href="http://www.url.com/" target="_blank"><img src="images/pic/logo.jpg" width="200" height="40" alt="alt text" border="0"></a></td>
</tr>
...snip...
I thought (obviously wrongly) that this would then generate the name of the page as indicated in the first part. But the output is simply in big bold letters:
.$pgname.
Put the page name here
<?
// Name of this page
$pgname = 'Put the page name here';
?>
I thought maybe because it's calling an include file that it can't display the page name in that way - that perhaps it need to be in the main file. The problem with that is that the page name is literally in the middle of the header - which I want to be referenced from an include file.
Any and all help much appreciated.
Instead of <?=$variable?>, it's probably better to do this the longer way:
<?php echo $variable?> - <?php is the 'long', 'more official' opening tag, echo is sort of like a function (only offically it's a language construct if we insist on splitting hairs) that outputs stuff to the browser (i.e., makes you see it on a page) and?> ends the php, makes the rest just get interpreted like ordinary HTML.