• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 360
  • Last Modified:

Server Side Include on plain .htm file on PHP server

I'm trying to help a client setup SSI's on his site. I believe its a Linux host, I don't have access to change any settings though:

http://www.pearson40.net/sample.htm

Code: <?php include("_head.htm"); ?>

I can't run ASP includes. I can run PHP includes, but only if I give it the PHP file extension. He has dozens of inter-linked pages with the .htm extension. Is there any way to do includes in that case, or are we out of luck? Thank you!
0
Brad Bansner
Asked:
Brad Bansner
  • 7
  • 4
1 Solution
 
stu215Systems AnalystCommented:
Assuming its linux you could use an .htaccess file to change the directory permissions to allow SSI commands.

Helpful Link:
http://www.besthostratings.com/articles/enable-cgi-php-ssi-htaccess.html

Sample .htaccess file :

AddType text/html .shtml
AddHandler server-parsed .htm
AddHandler server-parsed .html
AddHandler server-parsed .shtml
Options Indexes FollowSymLinks Includes
DirectoryIndex index.htm index.html index.shtml index.asp index.php
Options -Indexes
0
 
Brad BansnerWeb DeveloperAuthor Commented:
I made an .htaccess file and put your sample in. Reloaded page:


<!-- #INCLUDE FILE="_head.htm" -->

<p align=center style='margin:0in;margin-bottom:.0001pt;text-align:center'>&nbsp;</p>
  <p align=center style='margin:0in;margin-bottom:.0001pt;text-align:center'><b><span
  style='font-size:13.5pt;color:blue'>Go to the </span><a

So it isn't taking my SSI, or am I not doing this right?
0
 
stu215Systems AnalystCommented:
Try the following SSI statement to see if they are working:

<!--#ECHO var="DATE_LOCAL" -->

You may need to use:
<!--#include virtual="_head.htm" -->

Link to Wikipedia abt Virtual vs File for SSI:
http://en.wikipedia.org/wiki/Server_Side_Includes

Includes the contents of another file or the result of running a CGI script. If the process doesn't have access to read the file or execute the script, the include will fail. "virtual" specifies the target relative to the domain root, while "file" specifies the path relative to the directory of the current file. When using "file" it is forbidden to reference to absolute paths. Higher directories (..) are usually forbidden, unless explicitly configured. The Apache documentation recommends using "virtual" in preference to "file".
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
stu215Systems AnalystCommented:
Other things to check are the permissions on the .htaccess file.
[ The CHMOD of an htaccess file should be 644 or (RW- R-- R--). ]

And:  Uploading files in an FTP program happens in one of three different modes. Auto, Binary and Ascii. When you are uploading an htaccess file, it must be done in Ascii mode. To avoid all of the initial errors, make sure the setting is on Ascii.


Link to info on .htaccess files:
http://httpd.apache.org/docs/1.3/howto/htaccess.html
0
 
Brad BansnerWeb DeveloperAuthor Commented:
<!--#ECHO var="DATE_LOCAL" --> does work.

Changing to <!--#include virtual="_head.htm" --> does not work.

Reuploaded .htaccess making sure it was ASCII mode.

Not sure what else to do. I don't have access to the server in order to check permissions. If I can't fix this I'll have to resort to making everything .PHP files.
0
 
stu215Systems AnalystCommented:
If the Echo statement worked then its probably an issue with the file.

Try putting the path to the file from your server root:
<!--#include virtual="/<some folder>/_head.htm" -->

Make sure the file name is exactly the same...

Not quite sure what else to suggest :-(
0
 
Brad BansnerWeb DeveloperAuthor Commented:
Yeah, when I look at the source code of the page, I see this:

<!-- #INCLUDE virtual="_head.htm" -->

...so the web server isn't even processing the include as an include, its just serving that commented out code alongside all the other HTML.
0
 
stu215Systems AnalystCommented:
Random thought:
What if you turn on php for your .htm / .html files which would be similar to turning it on with the SSI

and use php includes:
<?php include("header.php"); ?>

Link to info about php includes:
http://www.w3schools.com/php/php_includes.asp
0
 
stu215Systems AnalystCommented:
Note: turning on SSI or PHP processing for all your pages creates a lot of overhead processing which can slow down your webserver so neither way is terribly great ...

I think eventually you will want to change them...

-- Doh, forgot you cant change the server settings... forget about the php includes on html files...
0
 
stu215Systems AnalystCommented:
If you can download the site to a local linux box or something you could do a search and replace on the whole directory to change things which wouldn't be too bad.

On windows you could use an app such as Dreamweaver CS5 which has nice site management tools and updating features.

Free Trial: https://www.adobe.com/cfusion/tdrc/index.cfm?product=dreamweaver&loc=en_us
0
 
Brad BansnerWeb DeveloperAuthor Commented:
OK, coo. Thanks for all your help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now