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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting header and footer in HTML

Status
Not open for further replies.

c4n

Programmer
Mar 12, 2002
110
SI
Hello,

This is what I am want to do and need your advice. I wrote a sort of a membership script (where users can login, view their statistics, edit their details etc.) and I want to be able to easily edit header and footer of the page. Not a hard thing to do, I know, but I fear that my solutions might use too much server resources if this membership site becomes popular. So I'd like to know how you do it for large membership systems.


Example:
I have HTML code for header in header.txt and HTML code for footer in footer.txt. Now the HTML page that the script generates looks like this:

<html>
<head>
head stuf here...
</head>
<body>
NEED HTML CODE FROM header.txt HERE
<some more html code>

</some more html code>
NEED HTML CODE FROM footer.txt HERE
</body>
</html>


Header and footer are required on many places within the script since it can print out many different HTML pages. I came up with two solutions:

1.
open(HEADER,&quot;header.txt&quot;);
@header=<HEADER>;
close(HEADER);
and then just use
print @header;
everywhere I need the header.

As you probably know, this solution is not memory-friendly so it is not the best idea.

2.
open(HEADER,&quot;header.txt&quot;);
while (<HEADER>) {chomp; print &quot;$_\n&quot;;}
close(HEADER);

I like this one better, but I fear this would mean a lot of opening and closing of files as, like said before, I need header and footer on various palces within my script.


Which solution do you think is better (uses less resources)? Any better ideas on how to insert header and footer in a script that is accessed a few 1000 times per hour?

All ideas welcome! Thanks in advance.
 
What I've done on my site is write a couple of little library procedures that print out the header/footer lines when I call them. They live in a seperate file that I include into whatever script needs them. I can also use SSIs to include them into static pages. In my case, the header and footer texts are hard-coded into the procedures, but they could open a file instead just as easily.

Frankly, I wouldn't worry too much about it. Go with whatever way you're comfortable with and change it later if you find you have problems. Putting the print-a-header-here code into a procedure will make it easier to change later if you have to.

-- Chris Hunt
 
Yea, you are probably right, I shouldn't worry aboutit too much. I'll go with the 2nd option and do some more research if it uses too much resources.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top