Forum Moderators: coopster

Message Too Old, No Replies

Can I run .php and an .htm SSI on the same page?

I've looked all over the WW forums for a *definite* answer... no dice.

         

timothius

2:17 pm on Dec 19, 2009 (gmt 0)

10+ Year Member



Hey all,

I just had a quick question which the answer to which would end a lot of grief and suffering for me... :)

Every page on my site (uses .html extension) uses SSIs that have an .htm extension.

Now I am adding php functionality and programming to all those same pages. I can get the .html pages to parse the php using this directive:


AddHandler x-httpd-php .html

HOWEVER, when that happens all the .htm SSIs don't show up.

Is there a way I can get both the php and the .htm SSIs to render properly?
Thanks!

rainborick

3:39 pm on Dec 19, 2009 (gmt 0)

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



I'm not sure what you're asking. You can't have a single page parsed twice - once with PHP and then with SSI. When you set AddHandler in your .htaccess file, you are overriding any default settings and selecting a parsing method for all of the files with the file name extensions in the instruction.

However, you should be able to use PHP to do just about anything you could do with an SSI instruction anyway. So you should be able to replace the SSI pages with pages coded with PHP.

timothius

3:46 pm on Dec 19, 2009 (gmt 0)

10+ Year Member



I would prefer to keep the .htm Server Side Includes as they are much easier to edit using Dreamweaver. I can't have any kind of 'live view' using php includes with my current setup.

I would also need to change every page of my site to use php includes and re-upload every page of my site which probably wouldn't be worth it.

I'm not quite sure what you're saying either... what's getting parsed twice? SSI is a parsing method? I'm using the SSIs to handle site navigation, footers, etc. so that I can easily make a change to single file and everything will update. Sorry, I guess I don't know all that much about SSIs when I say that I don't understand the phrase "once with php and then with server side include". It's just html...

If I'm confusing you, just see my original post again. :)

rainborick

9:00 pm on Dec 19, 2009 (gmt 0)

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



Yes, SSI is a parsing method. The server reads the file, interprets/parses it, and then serves the resulting content to the user. Same goes for PHP, but instead of SSI instructions, the page gets parsed for PHP code. So if you have a file that contains both SSI instructions and PHP code, only one of those two will ever be processed by the server.

Based on what you've said here, my advice would be to remove the PHP "AddHandler" instruction in your first message from your .htaccess file and replace it with:

AddHandler server-parsed .html .htm

Then put all of your PHP code in external files with a .php extension and use:

<!--#include virtual="external.php"-->

to incorporate the PHP support in your .html pages as needed.

rocknbil

10:55 pm on Dec 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's just html...

But by telling the O.S. to parse .htm pages for SSI directives, its not html any more. The way SSI works is it reads in the page looking for directives and alters the output dynamically. The "read in" process is called parsing, in the same way PHP parses a script for commands. The script doesn't "execute," PHP executes based on the commands you give it in the script.

The last example is what I'd do. Make a choice and choose one or the other - you can have both, but not both on the same page. So if you have a long list of .htm pages that are static except for the header includes, stick with SSI, or alter the SSI to include output of a php script. If you have pages that **must** use php outside the SSI directives, make them .php - but if it was previously indexed as .htm, a simple rewrite will minimize any SERP damage:

RewriteRule ^oldpage.htm$ oldpage.php [R=301,L]

timothius

2:48 am on Dec 20, 2009 (gmt 0)

10+ Year Member



Thank-you both for your replies! rainborick's suggetion to include the php files works. However....

In the .html pages I have to manually set a php variable to a numeric ID when I include the .php file. What's the best way to do this?

This is how we were planning on doing it:

<?php $PRODUCTID = "1"; include('Aproductinfo.php'); ?>

New way:
<!--#include virtual="/Aproductinfo.php"-->

Doesn't seem to be possible to feed the php include the variable...?

rocknbil

9:53 pm on Dec 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




<!--#include virtual="/Aproductinfo.php?PRODUCTID=1"-->

?

timothius

5:07 am on Dec 22, 2009 (gmt 0)

10+ Year Member



Wow - perfect rocknbil!

Just wondering if this method has any negatives that going with a php parser wouldn't have? (as opposed to remaining with ssi)

Thanks!