Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

We currently have SSI set up to work in our HTML pages as follows

<!--#INCLUDE file="/includes/header.inc"-->

We also use PHP on our server, and are trying to avoid creating two separate templates for PHP and HTML to include the same file. I know that in PHP I could include the file with the following command.

include 'header.inc';

This won't work in an HTML page, so is it possible to configure IIS 7 to have the #include directive work in both HTML and PHP pages? Is there a better way to do this period?

share|improve this question
add comment

3 Answers 3

up vote 5 down vote accepted
+100

This won't work in an HTML page, so is it possible to configure IIS 7 to have the #include directive work in both HTML and PHP pages? Is there a better way to do this period?

Something that might simplify things for you overall would be to configure IIS to use PHP code inside .html files instead of .php files. Then you'll be able to use PHP code directly in your HTML pages, and can use either the #include directive or PHP's include.

To do this in IIS 7, follow the steps covered here: Configure IIS to Handle PHP Requests, but change: Request path: *.php to -> Request path: *.html

share|improve this answer
    
+1 Thank you for the suggestion, and while this will work we really want to keep HTML pages as HTML pages, and PHP pages as PHP pages on our server. We have decided to go with two templates as there appears to be no other solution for this. IIS doesn't allow for multiple mapping of handlers as far as we can tell. –  Blake Plumb Sep 5 '13 at 14:23
    
No problem. Your original question had: "We have recently started to use PHP on our server", so it was more pertinent to that. Can you make the changes an "Update" to the question instead? I'm still testing alternatives... –  dan Sep 6 '13 at 22:44
    
@BlakePlumb Thank you for the accept. I've tried various workarounds, such as trying to map multiple handlers using web.config as suggested here, but couldn't get it to work. The problem is stuck in my head now, so if it comes to me, or I come across another solution, I'll comment back here. –  dan Sep 12 '13 at 1:50
add comment

I think your instinct is right Blake, avoid adding .html/.htm to the PHP Engine if not absolutely necessary. PHP documentation slightly touches on the fact this could have a performance impact, but doesn't get into a lot of detail... in an article talking about hiding PHP from attackers/visitors.

See PHP Documentation: Hiding PHP

Your question, based on the subject line of this thread is deduced as, [Are there] includes that work in HTML and PHP in IIS 7 on Windows Server 2008 [?].

If you already have SSI enabled on IIS, then doesn't this already work in PHP as regular html, the way you have been doing it? Or are you looking for yet a 3rd include option that isn't SSI module or PHP engine/include function that works in both HTML and PHP code? If SSI does what you want, and you already have that loaded on your Windows server and have dedicated time and resources developing and securing it, AND it works with PHP, why look for another option? I don't mean this to be confrontational, just trying to learn a little bit more about the problem you are trying to solve.

Otherwise this works just the same:

.html Files

<!--#INCLUDE file="/includes/header.inc"-->

.php Files

<?php
echo "<!--#INCLUDE file=\"/includes/header.inc\"-->\n";
?>
share|improve this answer
1  
Are you sure you can use both PHP and SSI together like that? I don't think it works that way. –  John Conde Sep 6 '13 at 13:09
    
In order for .html pages to work with SSI you have to map it through the server side include module, while PHP runs through the fast cgi module. I can map .php pages through the server side include module, but then it renders as HTML not PHP. The third option we have considered is using javascript to include the header, but again not exactly the best solution. I thought there would be a way to make SSI work in PHP as it does in asp.net dotnetperls.com/ssi –  Blake Plumb Sep 6 '13 at 14:39
    
@Eric Given that the static HTML would run under FastCGI, there wouldn't be much of a performance impact. –  dan Sep 6 '13 at 22:49
add comment

Check these links: http://tech.mikeal.com/blog1.php/server-side-includes-for-html-in-iis7 http://www.iis.net/configreference/system.webserver/serversideinclude

Hope that could help.

share|improve this answer
    
Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. –  John Conde Sep 6 '13 at 11:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.