static navbar from external file
I've heard it's possible with Perl to have a .html and then to "include" that file into another .html file. It'd be great to have a static navigator bar that didn't need frames. Can anyone point me to an example or tutorial of this?
Jim Shilt posted this at 00:39 — 6th January 2001.
They have: 268 posts
Joined: May 1999
All you need to do is create the file that contains your navigator bar. Save it in a file with a .inc extension. Then you place it in the file where you want it with the following.
Some isp's require that your html pages have a special extension so that server side includes (SSI) are recognized. Usually it is .shtm or .shtml
Let me know if you need more help
My goal in life is found in Phillipians 4:8-9
shoutingrock.org/troop214
IanD posted this at 03:07 — 6th January 2001.
They have: 222 posts
Joined: Sep 1999
I know, but I've never been able to get that to work...
Mark Hensler posted this at 04:52 — 6th January 2001.
He has: 4,048 posts
Joined: Aug 2000
make sure your host supports SSI
exbabylon posted this at 05:06 — 6th January 2001.
They have: 61 posts
Joined: Aug 2000
Try this code in a cgi script.
#!/usr/bin/perl
$file = $ENV{'QUERY_STRING'};
print "Content-type: text/html\n\n";
if($file eq "") {
print "document.writeln('<center><font color=red>Include Error: No File Specified.</font><br>');\n";
exit;
}
open(DATA,"$file") || print "document.writeln('<center><font color=red>Includer Error: Could not open $file ($!).</font><br>');";
@filecontent = <DATA>;
close(DATA);
foreach $line(@filecontent) {
chomp($line);
$line =~ s/\'/\\\'/g;
print "document.writeln('$line');\n";
}
Copy to NotePad name it include.cgi and place it in a cgi-bin. chmod 755. Make sure to upload in ASCII! Not auto or binary! Only customazation required is the path to perl... which should be AOK... although you may have to change it.
To "include" an hmtl file do this place this code in a regular html page... with the .htm or .html extention.
<script src="/cgi-bin/include.cgi?test.html"></script>
text.html would be the file you want to include on the page you put this tag on. If test.html is in a different directory you should include the full unix path infront of the fle name. If test.html is in the directory above the page it should appear on, you can just put
<script src="/cgi-bin/include.cgi?../test.html"></script>
NOTE: this should also work with .txt and other ASCII files (other cgi files, txt, xml, shtml, ect.)
this should work out just fine... if you have lots of dirs of your site you might want to consider using absolute paths (as I used for the example to the cgi-bin...) to the include file.
If you have any problems let me know and I'll help you out!
God Bless
Alex
[=1]Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.[/=1]
exbabylon posted this at 05:09 — 6th January 2001.
They have: 61 posts
Joined: Aug 2000
forgot to mention that the file will NOT open a binary file... (flash, picture, applet... or the like) but the HTML file can call that
Rob Pengelly posted this at 21:30 — 6th January 2001.
They have: 850 posts
Joined: Jul 1999
exbabylon,
$file = $ENV{'QUERY_STRING'};
What if the Query_String was '/etc/passwd'? If you do it that way, there should be some type of validation to make sure no '/' is present in the variable.
I was bored, so I modified your code a little:
#!/usr/bin/perl
my $file = "menubar.txt";
print "Content-type: text/html\n\n";
local $/;
{
open(DATA,"$file")or die "document.writeln('<center><font color=red>Includer Error: Could not open $file ($!).</font><br>');";
$content = <DATA>;
close(DATA);
}
$content =~ s/\'/\\\'/g;
print "document.writeln('$content');\n";
exit;
Obviously this will only work for one file, in this care 'menubar.txt'. It is executed the same way, with
<script src="/cgi-bin/include.cgi"></script>
http://www.thehungersite.com - http://www.therainforestsite.com
http://www.ratemymullet.com - Beauty is only mullet deep.
exbabylon posted this at 21:36 — 6th January 2001.
They have: 61 posts
Joined: Aug 2000
you're right.. DUH!
Thank's for the head's up!
sorry about that..
spragueg posted this at 17:47 — 8th January 2001.
They have: 23 posts
Joined: Jan 2001
Will variables placed in the external file using the ".inc" be parsed and replaced with data?
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.