We help IT Professionals succeed at work.

Including a PHP script's output in an SHTML file

I've got a text counter that works fine (as a .php3 file) and does what it's supposed to do; however, my page is based off of SHTML and as such is setup with several parts that make up a whole page.

I want to include this text counter into the page with a regular SSI tag: [!--#include file="counter.php3"--] However, when I do this, I get the message that "an error occurred while processing this directive," the typical SSI error message.

I know nothing of PHP, so any technical answer regarding the code of the script or how to modify it won't do anything for me :(

How can I get the output so that I can include it into my webpage?

(For more information, email me or check out the folder that the files are currently in: http://www.me.mtu.edu/~aeshirey/counter/ )
Watch Question

The problem is that it is not getting run through your PHP interpretor.

You see the web server knows that anything that ends (in your case) in .php3 needs to be opened by the server using the php interpretor - the interpretor then spits out the results of running the file and that is what is sent to the browser.

When you do an include into your shtml - (unless I'm wrong - which I could be) it is physically taking the PHP and putting into the document - just like you would HTML - this doesn't have the same effect though because the php is never ran through the interpretor - it is just physically copied into the document.

This is not to say I know how to fix this situation though.  I have not worked with shtml before - and really know nothing about it.  Hopefully someone else can be more helpful on that end.


Well, friedmud is correct. To insert a counter I would suggest you not to use SSI, but insert code like this:

<SCRIPT LANGUAGE="PHP3" SRC="counter.php3"></SCRIPT>

possible, that as LANGUAGE you should use not PHP3, but PHP. Try it.


Well, that got rid of the SSI problem; however, it now gives me no output. The source is as follows:


It's a step in the right direction, I suppose, but doesn't solve my problem :( (I should mention that I tried both PHP3 and PHP as the language.)

Once again,

Including it is not going to work - it never will.  This is the same reason why you can't use JSP and PHP in the same file either.  Because if you include one or the other - the one that is included doesn't get run through the proper interpretor and just does nothing.

You need to think of a way of displaying that counter without using an include - I think that is going to be the only way for you to solve this.

Good Luck!

I had this same problem trying to use a standard header file (as a SSI) with PHP script in a page.

The easiest way I came up with to solve this is to skip SSI completely and use PHP's built-in INCLUDE statement:

at the top and bottom of every page, and I can just put plain HTML in those files for my header and footer, and anything in the main page will be parsed properly because it is mainpage.php or whatnot.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.