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,"header.txt"
@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,"header.txt"
while (<HEADER>) {chomp; print "$_\n";}
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.
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,"header.txt"
@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,"header.txt"
while (<HEADER>) {chomp; print "$_\n";}
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.