HTML Server Side Include

If I use  <!--#include file="keywords.htm" --> in the head section of an html document & assuming the file keywords.htm is in the same web server directory was the file being included, shouldn't the source html in a browser show the included items?

For example look at www.anthonyirrigation.com/indext.htm.

Then view source, the included stuff is not there.

Do I have to enable SSI on the web server?

Thanks
Richard KortsBusiness Owner / Chief DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
<!-- anything here -->  is a comment  so it will be ignored.

If you want to include it's usually done as link.

more on including info here:
http://www.html5rocks.com/en/tutorials/webcomponents/imports/
Dave BaldwinFixer of ProblemsCommented:
Do I have to enable SSI on the web server?
Somebody has to.  SSI pages normally use '*.shtml' to invoke the SSI functions.

Your 'keywords.htm' has 8 instances of the keywords 'meta' so it should not be included like that anyway.  Only one instance per page.  And I'll note that you do not have a complete DOCTYPE at the top of the page so you are not controlling how your page will be rendered.
Dave BaldwinFixer of ProblemsCommented:
Here's one that I use to show the server variables.  Interesting in that PHP and other languages will show slightly different variables.  PHP may be more complete because it loop thru the $_SERVER variables while SSI has to have them explicitly listed like this.  Save it as 'servars.shtml' and see if your server will recognize it as an SSI page.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>SSI Server Variables shtml </title>
</head>
<body>
<h1>SSI Server Variables shtml</h1>
<b>DATE_LOCAL</b> = <!--#echo var="DATE_LOCAL" --><br>
<b>ALL_HTTP</b> : <!--#echo var="ALL_HTTP" --><br>
<b>HTTP_ACCEPT_ENCODING</b>: <!--#echo var="HTTP_ACCEPT_ENCODING" --><br>
<b>HTTPS</b> : <!--#echo var="HTTPS" --><br>
<b>SCRIPT_NAME</b> : <!--#echo var="SCRIPT_NAME" --><br>
<b>HTTP_COOKIE</b> : <!--#echo var="HTTP_COOKIE" --><br>
<b>AUTH_PASSWORD</b> : <!--#echo var="AUTH_PASSWORD" --><br>
<b>AUTH_TYPE</b> : <!--#echo var="AUTH_TYPE" --><br>
<b>AUTH_USER</b> : <!--#echo var="AUTH_USER" --><br>
<b>CONTENT_LENGTH</b> : <!--#echo var="CONTENT_LENGTH" --><br>
<b>CONTENT_TYPE</b> : <!--#echo var="CONTENT_TYPE" --><br>
<b>PATH_TRANSLATED</b> : <!--#echo var="PATH_TRANSLATED" --><br>
<b>QUERY_STRING</b> : <!--#echo var="QUERY_STRING" --><br>
<b>REMOTE_ADDR</b> : <!--#echo var="REMOTE_ADDR" --><br>
<b>REMOTE_HOST</b> : <!--#echo var="REMOTE_HOST" --><br>
<b>REMOTE_USER</b> : <!--#echo var="REMOTE_USER" --><br>
<b>REQUEST_METHOD</b> : <!--#echo var="REQUEST_METHOD" --><br>
<b>SERVER_NAME</b> : <!--#echo var="SERVER_NAME" --><br>
<b>SERVER_PORT</b> : <!--#echo var="SERVER_PORT" --><br>
<b>SERVER_PROTOCOL</b> : <!--#echo var="SERVER_PROTOCOL" --><br>
<b>SERVER_SOFTWARE</b> : <!--#echo var="SERVER_SOFTWARE" --><br>
<b>APPL_MD_PATH</b> : <!--#echo var="APPL_MD_PATH" --><br>
<b>APPL_PHYSICAL_PATH</b> : <!--#echo var="APPL_PHYSICAL_PATH" --><br>
<b>INSTANCE_ID</b> : <!--#echo var="INSTANCE_ID" --><br>
<b>INSTANCE_META_PATH</b> : <!--#echo var="INSTANCE_META_PATH" --><br>
<b>LOGON_USER</b> : <!--#echo var="LOGON_USER" --><br>
<b>REQUEST_URI</b> : <!--#echo var="REQUEST_URI" --><br>
<b>URL</b> : <!--#echo var="URL" --><br>
<b>SCRIPT_FILENAME</b> : <!--#echo var="SCRIPT_FILENAME" --><br>
<b>ORIG_PATH_INFO</b> : <!--#echo var="ORIG_PATH_INFO" --><br>
<b>PATH_INFO</b> : <!--#echo var="PATH_INFO" --><br>
<b>ORIG_PATH_TRANSLATED</b> : <!--#echo var="ORIG_PATH_TRANSLATED" --><br>
<b>DOCUMENT_ROOT</b> : <!--#echo var="DOCUMENT_ROOT" --><br>
<b>HTTP_ACCEPT</b> : <!--#echo var="HTTP_ACCEPT" --><br>
<b>HTTP_ACCEPT_LANGUAGE</b> : <!--#echo var="HTTP_ACCEPT_LANGUAGE" --><br>
<b>HTTP_CONNECTION</b> : <!--#echo var="HTTP_CONNECTION" --><br>
<b>HTTP_HOST</b> : <!--#echo var="HTTP_HOST" --><br>
<b>HTTP_REFERER</b> : <!--#echo var="HTTP_REFERER" --><br>
<b>HTTP_USER_AGENT</b> : <!--#echo var="HTTP_USER_AGENT" --><br>
<b>HTTP_ACCEPT_ENCODING</b> : <!--#echo var="HTTP_ACCEPT_ENCODING" --><br>
<b>HTTP_ACCEPT_CHARSET</b> : <!--#echo var="HTTP_ACCEPT_CHARSET" --><br>
<b>REQUEST_TIME</b> : <!--#echo var="REQUEST_TIME" --><br>
</body>
</html>

Open in new window

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
To Kyle Abrams,

Doesn't work.

Here are the first few lines of VIEW Source of the page.

<!DOCTYPE html>

<html>
<head>
      <title>Anthony Irrigation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="import" href="keywords.htm">

What I want it to do I hope is obvious
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
To all,

I checked with the web host (where you can communicate with real people ALMOST instantly), SSI is enabled.
Dave BaldwinFixer of ProblemsCommented:
Then you should be able to upload the file I posted as 'servars.shtml' and run it.
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
Dave,

I did that & it produces the attached. Don't know if that's right or not??

Thanks
servars.txt
Dave BaldwinFixer of ProblemsCommented:
Yes, that is exactly right.  Now you should be able to run your HTML file as '*.shtml' and have your 'include' work.  It's the '*.shtml' that tells the server to recognize the SSI commands.
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
Dave Baldwin,

I did that, it still doesn't work.

Does the "import" file have to be shtml too?

Thanks,

Richard
Dave BaldwinFixer of ProblemsCommented:
No, you didn't "do that".  Now you have "<link rel="import" href="keywords.htm">" in that page and that doesn't work anywhere at all.  I'll post a working example in a minute.
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
Dave,

I took "<link rel="import" href="keywords.htm">"  off what Kyle Abrhams said.

Are you suggesting I go back to the "comments" version?

Thanks
Dave BaldwinFixer of ProblemsCommented:
Here is a demo for you:  http://www.dibsplace.info/rkorts/SSI-Demo.shtml  Note that SSI does Not work without a web server to process the SSI commands.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
Dave,

That's all nice but NONE of this is accomplishing what I want.

I now kind of recall why I have NEVER gone down this path before.

Let me try to explain my objective.

In php, you can say include "php_file.php" on a line in a php script & it acts just is if the code in php_file.php was inline in the program with the include.

For example, I use a file I call "db_connect.php" in EVERY system I build that uses a MySQL database; then I just include that script in EVERY program.

I recently learned how to do that kind of thing in the <body> of an html page using Jquery. Works great. But that technique is based on a named div in the html and the Jquery " read function is used to insert into the <div> the desired html. Here is the exact code I'm using to do that:

Jquery:

$(document).ready(function(){
  $.get("footer.htm", function(data) {
    $("#footer").html(data);
  });
});

HTML:

<div id="footer">
      <!-- Content will be inserted by jQuery from footer.htm -->
</div>      

I was trying to accomplish the equivalent to include a file of keywords in the <head> section.

Richard
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
You get the points, I appreciate the effort you put in (and on other things).

Richard
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
On an aside, are you saying that there can be only ONE instance of <meta name="keywords" in an html file?

Richard
Dave BaldwinFixer of ProblemsCommented:
Thanks for the points but I guess you didn't look at the demo I posted then.  Here is the source code for SSI-Demo.shtml   You can't see the SSI commands/codes on the web page because they get replaced with the 'included' text.  I dont' actually recommend using this method if PHP is available to you since PHP can do so much more.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>SSI Demo</title>
<!--#include file="keywords.htm" -->
</head>
<body>
<h1>SSI Demo</h1>
<p>The text below comes a file an 'included' file.</p>

<!--#include file="keywords2.htm" -->
<p>And the 'meta' version is in the header which you can see in the 'View Source'</p>

<p>There is also <a href="SSI-Demo.htm">SSI-Demo.htm</a> here which you can see does Not work.</p>

</body>
</html>

Open in new window

Dave BaldwinFixer of ProblemsCommented:
On an aside, are you saying that there can be only ONE instance of <meta name="keywords" in an html file?

There Should be only one.  I can tell you that Google is probably going to ignore all of them in any case.  But especially if you include all of them.  That amounts to "keyword stuffing" and Google may penalize for that.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.