Forum Moderators: coopster & phranque

Message Too Old, No Replies

Personalized headers and footers...

...according to domain name

         

bresso

12:49 pm on Oct 12, 2003 (gmt 0)

10+ Year Member



Hello,

I own several domain names on which I have the same layout and content. I would like to differentiate the sites a bit by having personalized headers and footers for each site.

So I thought about having a script that will detect what domain name it's called from and display the according header and footer. (or maybe 2 scripts, one for header and another one for footer).

This way, I could avoid duplicating content that's basically the same... but still have personalized headers and footers for each site/domain name.

I hope you undertood what I was looking for... English is not my native tongue as you must have noticed... ;) Anyway, I was wondering if you guys could point me to some website, or to some resource that could help me reach my goal?

I believe it should be a pretty easy script for somebody in the know... Something like: if domain name=abcd.com, then header=abcd-header.html, if domain name=efgh.com then header=efgh.html, ...

Thanks a lot for your help!
Bresso

JasonD

1:04 pm on Oct 13, 2003 (gmt 0)

10+ Year Member



This should do it :)

# The domain name the server is responding on
$hostname = $ENV{'HTTP_HOST'};

# The header and footer files are based on the following
# directory structure. Change to suit your needs.

$header = "templates/$hostname/header.txt"
$footer = " templates/$hostname/footer.txt"

# Print the header
&head_foot ($header);

#insert rest of html here

# Print the footer
&head_foot($footer);

# The sub routine to read the header or footer files and
# print.

# N.B. Make sure you have already sent a content type
# e.g text/html

sub head_foot {
my ($headerorfooter) = @_;
open (IN, "< $headerorfooter") ¦¦ die "Could not open $header file\n$!";

my @lines = <IN>;

# process each line
foreach my $line(@lines) {
print $line;
}
}

bresso

2:00 pm on Oct 13, 2003 (gmt 0)

10+ Year Member



How exactly do I use this on the page? I was thinking about calling the script from a regular page. SO I'm slightly confused. Yes, I'm a newbie ;)

Thank you SO MUCH for your help! :)

JasonD

8:33 am on Oct 14, 2003 (gmt 0)

10+ Year Member



There are various ways you can call it.

Let's presume your site is coded in Perl (which I presume it is as you posted in the Perl forum)

Simply save the text in the post above in a file called headandfoot.pm and place it in the same directory as your main script.

Then place a line at the top of your script saying


require headandfoot.pm;
$hostname = $ENV{'HTTP_HOST'};

# The header and footer files are based on the following
# directory structure. Change to suit your needs.

$header = "templates/$hostname/header.txt"
$footer = " templates/$hostname/footer.txt"

Then wherever you want the header to appear place


&head_foot ($header);

or footer to appear


&head_foot ($footer);

If you site is in plain html let me know and I'll adapt this code to work via an SSI

Jason

bresso

12:27 pm on Oct 14, 2003 (gmt 0)

10+ Year Member



Hi Jason,

I would really appreciate it if you could tell me what to do to be able to use it on a plain html page via SSI.

Eric in Tennessee

2:40 pm on Nov 14, 2003 (gmt 0)

10+ Year Member



Jason and Bresso:

I thought that the Spiders disregarded (couldn't see) scripts?

If this is the case, I don't think that it will solve the duplicate content problem. I am just learning, so if I am incorrect on this, please forgive my ignorance.

I have just, today, started to learn about scripting.

Where do I start?

eTN