homepage Welcome to WebmasterWorld Guest from 54.211.95.201
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Apache Server Side Includes
How do I include output from a PHP file in an HTML file?
tolsen64




msg:4665332
 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.

Thanks!

 

lucy24




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

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.

tolsen64




msg:4665362
 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...

lucy24




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

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.

tolsen64




msg:4665398
 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.

lucy24




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

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:
[httpd.apache.org...]
:)

tolsen64




msg:4665424
 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...

not2easy




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

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...]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved