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!

Server Side Includes - I need help please 2

Status
Not open for further replies.

JennyW

Technical User
Mar 1, 2001
323
CA
SERVER SIDE INCLUDES

I want to make a site that has loads of pages.
The borders, menu and logo of this site are all images and all appear on every page on my site.

Right now, if I don’t use SSI and if I want to make changes to any re-appearing images on my site then I’d have to edit those changes individually - on every single page.

However, if I do use SSI, then I can edit those images once and my changes will be applied to every page.

I’m not too sure how I can go about doing this. Does anyone know how I can get started?

Thanks for reading,
Jenny
 
Ohhh, just to let people know, I'm not running my .cgi scripts with from Apache on my computer. I'm running them from my hosts server.
 
Well, here is a start:

To include a file in your webpage, you make a simple HTML comment like so:

[tt]<!--#include file=&quot;[/tt]

The C/C++ style #include tells Apache (I am assuming, or IIS) that there is going to be a file included. The file attribute tells the server what the file is that is included.

If you are on an Apache server, you must give your file extensions .shtml. Well, I kinda lied. Thats the default, and normally, hosts keep it that way. On an IIS run server, you might have to use .stm, or if they have it configured, you can use .shtml. The best bet is you give your host a little call or email asking them what the extension is for SSI files. You might even find it on their website.

Now, while that above includes a file, you might want to know how to execute a CGI script (this is useful if you want to include a counter or banner ad on your page).

You can do this like so:

[tt]<!--#exec file=&quot;[/tt]

OR (depending on how the server is set up)

[tt]<!--#exec cgi=&quot;[/tt]

I think, and hope that gets you started.

Hope this helps.

-Vic vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
Hi vcherubini!

This is how I’m understanding SSI:

1. I read that if I want specific html to display on a page I have to take that html and put it into a .txt file.
Then I insert that .txt file in my SSI call. Here’s an example:

<!--#include file=&quot;myfile.txt&quot; --> or <!--#include file=&quot;myfile.html&quot; -->

As you can see the second example above has an .html extension. I read you should only use .txt files within SSI calls, but some people use .html files. I couldn’t find the reason why. Does anyone know?

2. All of my websites pages use the same images (menu, header, footer, border).
However, some of my images have links on them and roll-over effects etc.
For example:
My Menu consists of several images. I understand that I can put all of my menu’s code and insert it in a .txt file and call it with an SSI command in all of my pages, but…

…what if some of the images on my Menu need code that’s in the < head > tag to function properly?

I know I don’t include the < html > < head > < title > and < body > tags in my .txt docs.

So, this is what I’m thinking…
I just insert the code for my menu in a .txt file (regardless of how many images and functions it has) and I leave the < head > code in the < head > tag of each pages original document (not the .txt doc).

This way when the SSI command calls the .txt file then the menu will function correctly because the html from that .txt file will be inserted into the html page, now that the html is part of the page it will then look for the < head > tags code in the original document.

Wooo. Am I right?

My fingers are going to fall off.

Thanks so much!
Jenny
 
Jenny:

You almost have it. :). Instead of having everything in a .txt file, just change the extension to .shtml.

For example, say you had a file called header.shtml and it looked like this:

[tt]
<html>
<head>
<title>
[/tt]

That was the entire file.

Then you have another file called afterheader.shtml and it looked like this:

[tt]
</title>
</head>
<body>
[/tt]

Then if you included those files onto the same page (call it index.shtml) like so:

[tt]
<!--#include file=&quot;this is the title
<!--#include file=&quot;[/tt]

That would make a simple web page with the title of it being &quot;this is the title&quot;.

Get what I am saying?

See the reason I say go away from .txt files is that some servers may not be set up to parse .txt file and may just let the browser do, which will just display the contents of the file.


Ok, now if you had a page with all the image links on them like so:

call it images.shtml
[tt]
<a href=&quot;page1.shtml&quot;><img src=&quot;myimage1.gif&quot;>
<a href=&quot;page2.shtml&quot;><img src=&quot;myimage2.gif&quot;>
<a href=&quot;page3.shtml&quot;><img src=&quot;myimage3.gif&quot;>
<a href=&quot;page4.shtml&quot;><img src=&quot;myimage4.gif&quot;>
[/tt]

That file could just be included onto the page with a simple SSI command.

Woo, that was a lot too. :)

Anyways, hope this helps some more and keep those questions comin'.

-Vic vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
thunx, Vic, that was really good explanation regards, vic
 
Hiee vcherubini and others!!

V-bini, you wrote:

Instead of having everything in a .txt file, just change the extension to .shtml…See the reason I say go away from .txt files is that some servers may not be set up to parse .txt file and may just let the browser do, which will just display the contents of the file.

Will all servers with SSI be set up to parse .shtml extensions versus .txt extensions?

Will anything go wrong if I use .shtml extensions?


Thanks for your post it was really helpful. I have to admit the layouts of your posts are very very easy to read (not hard on the eyes), most people don’t take that into consideration when posting.

Jenny
 
Well, here is my suggestion:

Call or email your host. Ask them what kind of extensions to use. Since you said they are using Apache, its a safe bet that .shtml will work fine.

You might even check their site. If they have an online manual, that might even tell you.

I don't know any other advice to give you. If .shtml extensions don't work, try .shtm or .stm. I have used both of those in the past.

Hope this helps.

-Vic

P.S. I would like to see how your site comes out when you are done with it. :) vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
Hi v-bini!
Ok, I checked my host and it seems that .txt and .html files are ok to use. I also tried using .shtml and it worked too!

However, I tried the simple SSI test you posted on July 5 and I wasn’t successful (“this is the title” – test).

Here were my results…


I checked my hosts FAQ and this is what they wrote:

My .shtml files don't display properly?
Apparently, sometimes the server is sending &quot;.shtml&quot; files as plain text, so all you see in the browser is the page's source. At least, you see the source in Netscape Navigator, but Internet Explorer shows the page properly, with the exception that any SSI directives don't work.
This is a server configuration problem, and it shouldn't be a problem with only your site, but for any account on the same server. You can fix this yourself by creating an .htaccess file in your &quot;html&quot; directory with the following lines:
AddType text/html .shtml
AddHandler server-parsed .shtml

The first line tells the server to associate &quot;.shtml&quot; files with the &quot;text/html&quot; mime-type. The second line tells the server to parse &quot;.shtml&quot; files for SSI directives.


To make an .htaccess file do I just open notepad, insert the two lines above and save it as a .txt file?
Will the .htaccess file be complete containing just the two lines written above?


==========================

I also have another problem. I was successful using SSI to call .html code that then called images. However, some of my images call code that’s in the < head > tag of my webpage, but after uploading and viewing the source of my page I noticed that all my < head > tag code relevant to my images’ function disappeared.

Why do you think this is happening?


Here are the five of the pages I uploaded. If you mouse-over the bicycle picture a white bullet should appear, but this isn’t happening because the code that’s suppose to be in the < head > tag is gone.


==========================

I was told I should use an external javascript file (<script src=&quot;menu.js&quot;></script>). What is this?

Thanks for reading!
Jenny
 
Ok. Sure, I can help :)!

First question:
When your host says to add these line:
[tt]
AddType text/html .shtml
AddHandler server-parsed .shtml
[/tt] to an .htaccess file, it means that you should open up Notepad and add those files, and then save the file as .htaccess. Just a . and htaccess, nothing else, that way, no one can view it in a browser. Try that and it should work just fine.

Second question:

Jenny, I have a question for ya.

You said:
&quot;I also have another problem. I was successful using SSI to call .html code that then called images. However, some of my images call code that’s in the < head > tag of my webpage, but after uploading and viewing the source of my page I noticed that all my < head > tag code relevant to my images’ function disappeared. &quot;

From what I can understand from this, you have html code, other than just
[tt]
<html>
<head>
<title>title</title>
</head>
[/tt]
before the [tt]</head>[/tt] tag? As in, there is more than just stylesheets there. What I am trying to say is that if you have more than just style sheets before your </head> tag, then you should take out that html and put it after the body tag. Try that.

And finally, an external JavaScript file means that the JavaScript code is not directly in with the rest of your HTML. It means the JavaScript location is referenced by the browser, and then the browser opens the JavaScript file, parses the JavaScript, and does what it needs to do.

Example:

Say I have the following in myscript.js:
[tt]
alert('this is a javascript alert');
document.write('hello world');
[/tt]

And I want to use that in my HTML code, I would do something like this:

[tt]
<html>
<head>
<title>JavaScript Includes</title>
<script language=&quot;javascript&quot; src=&quot;myscript.js&quot;>
</script>
</head>
[/tt]

That way, the JavaScript file woud be included into your HTML.


I really hope this helps, and I will try to get back to you as soon as possible.

-Vic vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
Hi v-bini!!

When your host says to add these line:

AddType text/html .shtml
AddHandler server-parsed .shtml


to an .htaccess file, it means that you should open up Notepad and add those files, and then save the file as .htaccess. Just a . and htaccess, nothing else, that way, no one can view it in a browser. Try that and it should work just fine.

I added the above two lines in a notepad document and saved it like this:
.htaccess

When I pressed save Notepad added a .txt extension to the end of the .htaccess file.
I uploaded the .htaccess file and it wasn’t’ visible (which I believe is correct) within my website files.



================================

I have some good news and some bad news. I usually start with bad, but today I’ll start with good. I got your simple SSI test running (“this is the title” test).


Instead of writing the below… [tt]

<!--#include file=&quot;this is the title
<!--#include file=&quot;[/tt]


I wrote the following… [tt]

<!--#include file=&quot;header.shtml&quot;;-->
this is the title
<!--#include file=&quot;afterheader.shtml&quot;;-->[/tt]


Here’s my webpage if you’d like to view my successful results with this test…



================================

Jenny, I have a question for ya.

You said:
&quot;I also have another problem. I was successful using SSI to call .html code that then called images. However, some of my images call code that’s in the < head > tag of my webpage, but after uploading and viewing the source of my page I noticed that all my < head > tag code relevant to my images’ function disappeared. &quot;

From what I can understand from this, you have html code, other than just

<html>
<head>
<title>title</title>
</head>

before the </head> tag? As in, there is more than just stylesheets there. What I am trying to say is that if you have more than just style sheets before your </head> tag, then you should take out that html and put it after the body tag. Try that.


Actually, the only scripts inside my < head > tag were javascript’s. I didn’t have anything else. My javascript’s just vanished?

================================

I can’t my get my external .js script to work.

I followed your example:



Say I have the following in myscript.js:

alert('this is a javascript alert');
document.write('hello world');


And I want to use that in my HTML code, I would do something like this:


<html>
<head>
<title>JavaScript Includes</title>
<script language=&quot;javascript&quot; src=&quot;myscript.js&quot;>
</script>
</head>


I followed the directions you posted above and I came up with unsuccessful results.

Here’s what my external javascript file looks like (named: javas.js in my /




Now, I call that script in my webpage, but the script doesn’t work or something, I’m not sure?

Here’s the page where my external javascript file is located:
After you rollover the cupid pic a snowflake should appear (javascript).
(if you view the soruce then you’ll see my .js code in the < head > tag)




Maybe it’s a problem with the path to my javascript file?

Here’s the path to my .js file:


<script type='text/javascript' src='./javas.js'></script>


Is type='text/javascript' correct?

Is src='./javas.js' right? (I also tried just src=’javas.js”)



Thanks for taking the time,
Jenny
 
Hello again.

To get rid of the .txt in your .htaccess file, when saving the file, click the Save As Type down arrow and click All Files. Then save it, and Windows will get rid of the .txt file.

Ok, I feel really embarrassed, I just saw a flaw in my code:

I had:
[tt]
<!--#include file=&quot;header.shtml&quot;;-->
this is the title
<!--#include file=&quot;afterheader.shtml&quot;;-->
[/tt]

I just saw that for some reason, I had put semi-colons at them end of the &quot;. You can take them out. That might solve a lot of your problems.


Ok, I see why your external JavaScript file is not working, take the [tt]<script>[/tt] and [tt]</script>[/tt] tags out of the file and it should work fine.

I think that answers all your questions.

I really hope this helps, and if you have any more questions, feel free to ask!

-Vic vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
Hi!

Well, I fixed the [tt]<script>[/tt] problem, but I’m still unsuccessful with my testing.

Here’s what my adjusted [tt]javas.js[/tt] script looks like:


Here’s the url to my page.

- If you view the source of the page above you’ll notice that nothing comes in between my < javascript > tags within the < head >.
- If you rollover the cupid then a snowflake should appear to it’s left. However, this isn’t happening.


I don’t know what I can be doing wrong?
I’m uploading all of my files in the www directory. I believe that’s right?

====================

Here’s a couple things that you might need to know:

- The status bar on the bottom of my page displays: [tt]Error on Page[/tt]
- The .txt docs my SSI calls have [tt]< div > < /div >[/tt] tags inside of them. Here’s the code of the document my SSI calls on:
====================

I tried going to Save as type and saving my .htaccess file without the .txt extension, but the .txt extension was still added.
So I tried entering the following:
.htaccess
The quotes helped a lot and the file was saved without the .txt extension. Was it ok to do this?

Do you think it’s possible that my page isn’t working because I have two .htaccess files uploaded on to my webspace?

.htaccess
.htaccess.txt


Thanks for your help, I really appreciate it!
Jenny
 
Ok, first with the javascript, you have something wrong in your very first line. The comment is wrong.

You have:

[tt]
< !--
[/tt]

Needs to be
[tt]
<!--
[/tt]

That should work fine.


I think that wrong comment is what's messing up your entire page.

You can delete the .htaccess.txt file from your server, its just taking up (a small amount of) space.

It always bugs me when I am programming and I get the entire program wrong because of one little piece of whitespace or something like that.

I think that should do it, if you have any more questions, keep on askin'.


As always, hope this helps.
-Vic

P.S. I always enjoy reading your posts, one of the few people who take the time to make them look neat. Thanks! vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
Success!
Thanks v-bini! Your help is very much appreciated!

If you want to check out my Successful results visit the following url:

You wrote:
* Ok, first with the javascript, you have something wrong in your very first line. The comment is wrong.

* You have:


* < !--


* Needs to be

* <!--

Actually, that wasn’t my mistake. I only made the comment like that for my javas.txt file because I couldn’t make the code viewable on a webpage unless I made that slight adjustment to it. (I have a question about this below).

My mistake was that I forgot to take the…

[tt]<script language='javascript'>[/tt] and [tt]</script>[/tt]

…tags out of my javas.js file. However, I did remember to take them out of my .txt file, which doesn’t help me at all. Oh well, like you said, little things can getcha sometimes!

=====================

Every time I upload < html > code to a webpage for people to view I have to put spaces in between some of the tags, so people can see the code I’m referring to.

How can I upload viewable < html > code to a webpage without adding spaces to the code?

=====================

Is it possible to call DHTML scripts using the External Javascript File method?
Can I put the DHTML scripts in my .js file?


Here’s what my DHTML script looks like:

Here’s where I got it:


I don’t necessarily want to use the DHTML script above. I just need to know if I can call them in a .js file?

=====================

Is it possible to use SSI to call < html > code?

=====================

Thanks you!
Jenny
 
Awesome, glad your site finally works! :)

Ok, since a DHTML file is essintially a JavaScript file, you can store all of the DHTML code in a .js file, and as long as the code is syntactially correct, it will work fine.

If you want to show people your code on the web, the way I would do it is as follows:

1. If you have a text editor that can do multiple search and replaces, (such as notepad on win2k or editpad from you can open up the HTML file you want to show and then search for '<' and replace it with '&lt;' and search for all '>' and replace them with '&gt;'. Those are the codes that will make the browser interpret the values literally, instead of parsing it like HTML. For example, say you have a [tt]<b>[/tt] tag and you want to print it literally. You can do the following:

Change:
[tt]<b>[/tt]
to
[tt]&lt;b&gt;[/tt]

Of course, like I said, if you have a text editor that can do multiple search and replaces, just search for the open signs and end signs of a tag and replace it with its literal value.

And finally, yes it is possible to call HTML with SSI. Just put the code in a .shtml file and call it from another .shtml file.

I can't wait to see your final site, BTW.

Hope this helps.
-Vic vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
Hi,

I’m having trouble calling a DHTML script within a .js file.

I have a DHTML script that creates color scrollbars (you can only view these scrollbars using IE5.5 and NS6).

Here’s the script I’m trying to call:


[tt]<!--
BODY{
scrollbar-face-color:#75EA00;
scrollbar-arrow-color:brown;
scrollbar-track-color:#333333;
scrollbar-shadow-color:'';
scrollbar-highlight-color:'';
scrollbar-3dlight-color:'';
scrollbar-darkshadow-Color:'';
}
-->[/tt]


- I took the < script > tags out of the above code.
- I inserted the code in to the same document my rollover javascript is in (javas.js).
- I then uploaded, and the scrollbar script didn’t work, and to make matters worse my rollover script stopped working.
- So, I took out the scrollbar script and left the javas.js file with only the rollover script in it. I uploaded it and the rollover worked fine again.
- Then I tried making a separate file called javas_002.js and I only put the scrollbar script in it. I put the following code in my webpage:

[tt]<script type='text/javascript' src='javas_002.js'></script>[/tt]

- I uploaded both the webpage and the javas_002.js script, but the scrollbars didn’t appear on the screen.


Here’s my page:


Here’s an example of color scrollbars:



I don’t know what I’m doing wrong?

====================

Thanks for explaining in detail how to display [tt]code[/tt] on webpages. I’ve been curious on how to do that for a while.
Jenny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top