Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Include Problem

Status
Not open for further replies.

alsaffar

Programmer
Joined
Oct 25, 2001
Messages
165
Location
KW
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 = &quot; if isset($_POST[UserID]) {?>onload\=\&quot;document.FormName.Field1.focus()\&quot;<?} else {?>onload\=\&quot;document.FormName.Field2.focus()\&quot;<? } &quot;;
include(&quot;Header.php&quot;);
?>
<form name=&quot;FormName&quot;>
<input name=&quot;Field1&quot;>
<input name=&quot;Field2&quot;>
</form>
<?
include(&quot;Footer.php&quot;);
?>

Please help me.
 
I've found that I get the best results from what you're trying to do if the calling script outputs all the <html> and <body> tag sets.

Here's a reorganization of your code:

Header.php
--------------
<?php
print 'header content';
?>

Footer.php
-------------
<?php
print 'footer content';
?>

Test.php
----------
<?
print '
<HTML>
<BODY ';
if (isset($_POST[UserID]))
{
print 'onload=&quot;document.FormName.Field1.focus()&quot;'
}
else
{
print 'onload=&quot;document.FormName.Field2.focus()&quot;
}
print '>';

include('Header.php');

print '
<FORM name=&quot;FormName&quot;>
<INPUT name=&quot;Field1&quot;>
<INPUT name=&quot;Field2&quot;>
</FORM>
';

include('Footer.php');

print '
</BODY>
</HTML>';
?>

Want the best answers? Ask the best questions: TANSTAAFL!
 
Thanx sleipnir214 for trying to help.

My original Header.php and Footer.php is much complicated than the one I'm showing. I'm showing only an example, if the example I'm showing is working then the original ones will work also.

My target is to declare the variable $BodyTag before including the Header.php, so <body> get effect from the varibale I'm declaring before the include statment.

Please guys be patients with me, I want my scripts to be debugged as they're and then notify me where do I have to alter.

Thanx again inAdvance for your help guys.
 
Why does the variable in question have to be calculated inside header.php? Could it not be calculated inside a header that is included before you start output?

I've found as a general rule that if you can restructure your code to avoid use of PHP's eval() function, you should do so.


Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top