Include Problem

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
User avatar
alsaffar
Forum Newbie
Posts: 16
Joined: Sun Sep 29, 2002 12:03 pm

Include Problem

Post by alsaffar »

Hi all,

I want to include a header page and a footer page for all my web pages.

Header.php and Footer.php have the border design of my website, so for all my pages I have only to include Header.php and Footer.php then in between the 2 include statments, is the code of any page.

So, when I want to change anything to the border design of my website, I'll only change Header.php and Footer.php, not to change for all my website pages (32 pages)

Now, in the Header.php there is the HTML Body tag <body> and in each page of website the content of the body tag is different than the others, so I think the solution to my problem is to have the content of the body tag to be in a variable $BodyTag so I can assign its contents before including the Header.php then I can make the body tag changed dynamically depend on the body tag variable $BodyTag.

The problem Im facing is not in the declaration of the variable $BodyTag, the problem is in showing the variable, I tried (echo) and (eval) but still I can't see the content of the variable when I viewed the source.

Please install the 3 scripts and debug, AT THE END, ONE OF THE 2 FIELDS SHOULD BE FOCUSED.

Here're the 3 scripts again

Header.php
--------------
<html>
<BODY <? ob_start(); eval('?>' . $BodyTag); $value=ob_get_contents(); ob_end_clean();?>>

Footer.php
-------------
</body>
</html>

Test.php
----------
<?
$BodyTag = " if isset($_POST[UserID]) {?>onload\=\"document.FormName.Field1.focus()\"<?} else {?>onload\=\"document.FormName.Field2.focus()\"<? } ";
include("Header.php");
?>
<form name="FormName">
<input name="Field1">
<input name="Field2">
</form>
<?
include("Footer.php");
?>

Please help me.
User avatar
releasedj
Forum Contributor
Posts: 105
Joined: Tue Jun 17, 2003 6:35 am

Post by releasedj »

Your body tag should look like:

Code: Select all

<html>
<BODY <?php echo $BodyTag; ?>>
User avatar
releasedj
Forum Contributor
Posts: 105
Joined: Tue Jun 17, 2003 6:35 am

Post by releasedj »

And the Test.php should look like:

Code: Select all

$BodyTag = ( isset($_POST[UserID]) ) ? 'onload="document.FormName.Field1.focus()"' : 'onload="document.FormName.Field2.focus()"';
Post Reply