Forum Moderators: phranque

Message Too Old, No Replies

Including PHP file in HTML document with SSI

Procedure works on one host, fails on another

         

MatthewHSE

12:38 am on May 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I thought about posting this in either the Apache or the PHP forums, but it involves so much of both of them that I couldn't decide which was most appropriate. So "Webmaster General" it is! ;)

I've got a handy little random-quotes kind of script that's written in PHP. The script runs through it's PHP stuff, then echos the quote. The idea is to then include the PHP script in another page, either using PHP includes or, if you're using standard HTML pages, using SSI.

So you've got the script that echos output, then a regular

<!--#include virtual="/path/to/quotescript.php" -->
SSI on the HTML page.

This procedure works great on one host I have an account with. On a new site I'm setting up, on a different host, I keep getting the old familiar

An error occurred while processing this directive
message when I try to call the script with SSI.

I've done all the obvious things, checked the path, looked over the SSI "syntax," ran the script alone in my browser to make sure it was working, etc. Everything checked out okay.

I then tried creating a new PHP file. I never even used

<?php
to start PHP processing the file, just wrote out some text and saved it. Then I tried to use SSI to include that file. It also failed, same error.

What I've narrowed it down to is that the server is happy to use SSI to include any file, regardless of extension, unless and until it's set to parse that file for PHP. As soon as I allow the server to parse the file for PHP, the SSI fails (even if I never even start PHP in the file in question).

After such a lengthy explanation, the question itself is disgustingly short. Why on earth won't the server include a file that's being parsed for PHP, when it's more or less the same server setup and configuration as another server that handles it flawlessly?

Any ideas on what to check or how to troubleshoot this will be greatly appreciated.

Thanks,

Matthew

jomaxx

1:21 am on May 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have PHP on 2 different servers, but they require slightly different syntax. There's probably an excellent reason but I am not a PHP expert so don't ask me what it is. All I know is I eventually settled on the format below and it works gud:

<?php
include "/path/to/quotescript.php";
?>

2by4

11:43 pm on May 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Why waste your time with the SSI part, just use php includes, they are much more reliable, cross hoster especially, all you have to do is set the include path for each hoster and you're off and running. I had a lot of problems trying to get ssi to run on some boxes, finally realized there was zero gained by using ssi compared to php, so now I just always use php.

Don't leave out the <?php .......?> it's bad practice, and makes your scripts open to hackers etc.

MatthewHSE

12:18 am on May 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why waste your time with the SSI part, just use php includes,

I have to use these includes on standard HTML pages. On these same pages, I have to include the HTML output of some CGI scripts, and so far I haven't found a way to get that with PHP includes. So for now it's SSI or nothing, unfortunately.

Incidentally, I tried creating a PHP file just to see if I could use PHP includes with this script, and it still failed. I don't know why. Actually I'm about to swap the site to a different host; this isn't the first Mickey Mouse problem I've encountered on this server and I'm just about through with them.

2by4

3:01 am on May 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



"this isn't the first Mickey Mouse problem I've encountered on this server and I'm just about through with them."

Oh, that kind of problem, say no more. Took me a while to realize that the constant problems I was having with cheapo hosts were costing me far more than the few dollars a month I was saving, since using higher end hosts I have no significant issues as a rule, and any I do have are always resolved asap, with no headaches.

Span

8:47 am on May 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have to include the HTML output of some CGI scripts, and so far I haven't found a way to get that with PHP includes.

If you make the server parse .html files for PHP with this line in your .htaccess:
AddType application/x-httpd-php .html
you can use:
<?php include ("file.inc.php");?> to include headers, footers and other PHP
and also include CGIs with:
<?php virtual ("/cgi-bin/program.cgi")?>