Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Apache Server Side Includes

How do I include output from a PHP file in an HTML file?



6:29 pm on Apr 23, 2014 (gmt 0)

In my html page, I want to include a hit counter by including a PHP document that will return the hit count for that page. So at the bottom of my HTML page, I want to do this:

<center>HitCount: <!-- #include virtual="HitCounter/phpHitcounter.php?pageId=rootDefault" --></center>

This doesn't do anything at the moment and I've been searching the subject and reading about setting options in the httpd.conf file to allow this. But most of them say that it only works with shtml files.

If the above code is possible, I'd sure appreciate some guidance on how to accomplish it.



7:37 pm on Apr 23, 2014 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

By default, includes only happen in pages with .shtml extension. But there are two alternatives if you don't feel like changing the extension of all your files. One involves the X-Bit Hack; use this if you only want some selected pages to use includes. The other involves an AddOutputFilter line.

I assume you've already set
Options +Includes

The other line is

:: shuffling papers ::

AddOutputFilter INCLUDES .html

Replace ".html" with whatever extension your pages currently use. This refers to the physical file, which might be different from your visible URL. This line means that all pages in .html will be checked for includes.

If includes aren't happening at all, you will see the
<!-- include blahblah
line in the html of the finished page, just like any other comment. If they're theoretically possible, but there was some other error, you will instead see the Include Error message. You will want to change this to something like
SSIErrorMsg "<!-- SSI error -->"
because the default error is a bit of plain text that's visible in the page if you know what to look for. Not helpful to the end user.


9:10 pm on Apr 23, 2014 (gmt 0)

Thanks. That's working now for .html and .htm files. Doesn't work for .php files but I think this might be happening if Apache sends .php files directly to the PHP parser. Time to start searching again...


9:38 pm on Apr 23, 2014 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Heh. If I'd known you also used SSIs in php files, I wouldn't have edited my cut-and-paste, which actually says (in my own htaccess)

AddOutputFilter INCLUDES .html .php

SSIs and php includes are entirely different animals. If you want to use SSIs in a page with .php extension, you have to say so, or the server won't know.

Is it really working on .htm files even if the line only says .html? I am surprised.


11:45 pm on Apr 23, 2014 (gmt 0)

It works because I added each file extension to the httpd.conf file:

AddOutputFilter INCLUDES .html
AddOutputFilter INCLUDES .htm
AddOutputFilter INCLUDES .php

But for .php it doesn't work. I'll try the .htaccess file and see if that does the trick.


12:54 am on Apr 24, 2014 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Oh, you're in config. Missed that. But in this area, htaccess vs config should make absolutely no difference. And I can't think of any situation where something that doesn't work in config will work in htaccess. (Other way around, yes.)

You can combine extensions in a single AddOutputFilter line; they're cumulative.

:: detour to check something further ::

OK, doesn't seem to make any difference whether they're combined or separate. I guess that's what you would expect from a directive in "Add..."

Do you have a SetOutputFilters line? I have to assume you don't have a RemoveOutputFilter anywhere, because those don't show up by accident.

If you like looking at diagrams, Apache's got two:


3:33 am on Apr 24, 2014 (gmt 0)

Well, I've tried just about everything I can think of.

AddInputFilter INCLUDES .php
AddOutputFilter INCLUDES .php
SetInputFilter INCLUDES
SetOutputFilter INCLUDES

I've tried each of these in the <Directory /mnt....> section and in the <IfModule mime_module> section. No-go on all tries...


4:12 am on Apr 24, 2014 (gmt 0)

WebmasterWorld Administrator 5+ Year Member Top Contributors Of The Month

I think you had it right before, tolsen64. Since the page is a "page.php", it gets processed just once and any SSI includes are ignored. I have pages with multiple php includes that all get included, but they are html or else served as html pages and I'm not using SSI includes like the type you have.

Maybe that part of the question, you could get a better answer in the PHP Forum: [webmasterworld.com...]

Featured Threads

Hot Threads This Week

Hot Threads This Month