Web Hosting Talk







View Full Version : Code to add header/footer banner dynamically like free web hosting people


powerrajesh
12-03-2003, 04:36 PM
Hi,

I wanted to code to add header/footer banner dynamically like free web hosting people.

So, i wrote .htacces and a simple php file to this task. Even though i am successful with this, i have doubt, whether this is correct way adding banners.

I am pasting the code here. Experts please help me. Tell me the validity of this code.

If anyone using this code, please tell me whether you are happy with the code.

.htaccess
=======
RewriteEngine on
RewriteRule ^(.*)\.html$ /t.php

t.php
===

<?
$filename=$DOCUMENT_ROOT.$REQUEST_URI;
$handle = fopen ($filename, "r");
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
echo $contents;
echo "<DIV ALIGN='CENTER'>banner</DIV>";
?>


My question is whether this code is correct? Will it kill the CPU? or is this a normal method of using .htaccess and php?

Regards,

<Liaison Note: Signatures must be setup in your profile>

Burhan
12-04-2003, 05:08 AM
I don't know if this is the "normal" method of doing such things -- but I have some other suggestions.

Using mod_rewrite, you can launch a shell script whenever a file is requested, and then just add the banner to the requested file.

$ echo "<div align='center'>banner</div>" >> filerequested.html

Something like that.

Just something to consider. I can't say with certainty if that's more efficient/less cpu intensive -- but usually shell programs (written in C) are faster than PHP.

Just my $0.02

nnormal
12-05-2003, 04:41 PM
o.k. me no expert but are you just trying to use header/footer templates so you dont have to code a menu on every page or something??

if so then use the

include ('headerpage.html');

(don't know how that code will look)

nnormal
12-05-2003, 04:43 PM
code looks right:agree:

Sheps
12-05-2003, 08:08 PM
look around for mod_layout if you have root access...

kneuf
12-07-2003, 11:02 AM
just another thought, isn't there something in the php config file that adds stuff to every page? or is it just php files?

powerrajesh
12-07-2003, 01:07 PM
Hi everybody,

I am successfully running the code. First i was having a problem while opening http://www.domain.com or http://www.domain.com/directory. Because, this does not return any filename. However, now i have solved the problem.

The code is running for the last 3 days. Until now. i have not receveived any bugs.

Anyhow, if there is any other method better than this, please tell here.

Regards,

<Liaison Note: Signatures must be setup in profile>

EXOWorks
12-07-2003, 04:36 PM
Apache AddHandler can help a lot, just read about it in the apache documentation. You can come up with a better way.