PDA

View Full Version : Help with SSI includes clashing with PHP



Morgenmuffel
07-11-2008, 02:21 PM
Hi all

Here goes

the site is all .shtml files, and there is a feedback form that used to use a perl script i say used to as the perl script is missing.
I have no familiarity with perl and the said script from what i have found on the net is a generic one that was last updated in 2005, so is probably not that secure

So i decided to make the form in PHP, which i do know and I know how to make it fairly secure. The headers and footers etc are all .shtml includes, i have got them all working within my php page by replacing


<!--#include virtual="/inc/top.shtml" -->
with

virtual ('/inc/top.shtml');

which works perfectly except for that html variables that are pulled from an if statement on another include file don't seem to work, Ok let me rephrase that the default values (the top two lines shown below) do come through, however the ones that should come through from the if statement don't, my guess is this is to do with the way the ssi handles the file paths within the actual if statement ($DOCUMENT_URI=/^\/index.shtm/) is there a way i can fix this. remember this file is called from within a file that my form is calling

the if statement is in this form



<!--#set var="TITLE_H1" value="Products" -->
<!--#set var="TITLE" value="$TITLE || Inventory" -->

<!--#if expr="$DOCUMENT_URI=/^\/index.shtm/" -->
<!--#set var="TITLE_H1" value="Welcome to Bobs Big Bits" -->

<!--#elif expr="$DOCUMENT_URI=/^\/form/" -->
<!--#set var="TITLE_H1" value="Form" -->
<!--#set var="TITLE" value="$TITLE || Form" -->


I can't really change anything that will effect other pages, as all other pages on the site call the "top" & "bottom" includes. the "variable" include (the one with the if statement) is called by the "top" include, I have a feeling this could be something to do with the problem

I have kludged it for the time being by putting the condition I want as the default condition and adding an else statement to the If statement with the original default so that should work (well it does)

Is there a proper way to do this?

Erayd
07-11-2008, 03:03 PM
The problem is you are expecting ssi and php to pass variables transparently - it doesn't work like that. See here (http://nz.php.net/manual/en/function.virtual.php), noting this bit especially:
Note: Environment variables set in the requested file are not visible to the calling script.

Xavier
07-11-2008, 03:52 PM
why not use include ? include parses the variables inside another file so long as the variable is defined before the point of include?

Erayd
07-11-2008, 06:49 PM
why not use include ? include parses the variables inside another file so long as the variable is defined before the point of include?

Because the files he's trying to include aren't PHP files, they're SSI, and therefore need to run through apache first. If he switched to include or require, he'd need to completely rewrite the affected files in PHP.

Morgenmuffel
07-11-2008, 06:49 PM
The problem is you are expecting ssi and php to pass variables transparently - it doesn't work like that. See here (http://nz.php.net/manual/en/function.virtual.php), noting this bit especially:
I realise that, i have never really used SSI within PHP before, well once and it took me a devil of a time to figure out that i had to put the full path in
(/home/nigel/public_html/include/top.shtml
And that is my complete and utter experience of SSIs, I have just taken over looking after a site that is 100% SSIs


why not use include ? include parses the variables inside another file so long as the variable is defined before the point of include?
I did try include(/home/nigel/public_html/include/top.shtml) to start with and that made some of the "top" include appear BUT it wouldn't include any of the SSI includes that were within the "top" include, owing to the way the paths have to be defined.

It took me a hellish amount of time to figure out the Virtual thing (should have been obvious, but oh well)

I also couldn't put the variables before the include because they were then overwritten by the defaults (I'm guessing here as the page was pretty empty because none of the includes called by the "top" include were there), and I needed to include all the includes which using the php virtual() did.

Morgenmuffel
07-11-2008, 06:53 PM
Dammit you beat me there Bletch

Anyone heard of this script, its the one the site was using, but is missing, I can't seem to find a recent version of it. I am probably going to stick with PHP as it is a bit easier to lock down (for me at least)

mailform.pl

just curious?

Erayd
07-11-2008, 07:05 PM
What is the script? You've only given us the name, and to be honest I've seen a zillion perl scripts called mailform, all of them different. Where did you get it from?

Morgenmuffel
07-11-2008, 07:13 PM
What is the script? You've only given us the name, and to be honest I've seen a zillion perl scripts called mailform, all of them different. Where did you get it from?

I don't have the script thats the main issue, i have seen a few versions on the net and i assumed they were all the same standard script.

I think I'll stick to PHP, i'm not enjoying having to think right now