QUOTE(Brian Chandler @ Jan 25 2007, 04:37 AM)
<!--#include virtual="demo.php?a=fixed" -->
isn't going to "work". Apache includes include *files*; the arguments on the end are something interpreted by a Web server. (Yes, I know Apache is a server, but when it gets a file to include it can only get the file.)
Please don't think that I am being contrary for the sake of it - but it does work.
When I found that it was posible to pass parameters via Apache SSI like this then I thought that my hack approach was going to be feasible.
You've lost me, I'm afraid. I am only guessing at how the php interpreter gets a file from an SSI. You say it "works" and I would have to believe you, but then you seem to say that it doesn't work after all.
What I was referring to as working is that including a query string in the SSI #include does result in the query being passed to the invoked .php in the _GET/_REQUEST etc.
Hence my contrived example of ?a=fixed
What I was referring to as not working was my hoped for overall approach - i.e. have the query string from the outermost call (i.e. bit after the ? in http://somewhere/demo.htm?a=outermost
) making its way through transparently in the same way.
===Post #10 PW:
I've just put those 2 pages on a site just to show what happens
replace the "somewhere" from post#5 above with www dot dandelionradio dot com
As you will see the #include with the ?a=fixed really does pass the parameter to the PHP script.
I can't see much, really, because I can't see the script itself. But it looks as though (perhaps) an SSI puts the params to the "include" in the following variable:
But why should that help? Does the php script only/always look at this particular variable? How is the php script originally meant to be used? If as a standalone page, then it will probably look for its parameters in the $_GET array (which is what I suggested to you).
The demo.php and demo.htm that are on that site are essentially the same as the example that I first wrote in #5 above - but I later included some code in the .php file to dump out the environment variables and I spotted that _SERVER["REDIRECT_QUERY_STRING"] and _SERVER["REDIRECT_QUERY_STRING_UNESCAPED"] had the query string. IN fact, if you look at my very first post you will see that I was trying to use something like that having spotted references to QUERY_STRING_UNESCAPED ... but I hadn't realised at the time that the real name was slightly different (i.e. it ihas "REDIRECT_" on the front..
Regarding $_GET - as I mentioned above - the script uses $_REQUEST. $_REQUEST includes _get, _post and _cookies ... i.e. it is (sort of) using _GET.
So - given that _SERVER["REDIRECT_QUERY_STRING"] contains the original query string ... I have (in my latest version of the real script - but not in the demo.php) replaced all references to $_REQUEST with a function call. In this new function I look in $_REQUEST and if the required value is not there then I use parse_str on $_SERVER['REDIRECT_QUERY_STRING'] to see if it is in there.
This revised code is now working fine for parameters that come in via the query string.
Meanwhile I am having a go at gettinghte php inside the .html method to work.
Again, I'm lost. What is the "php inside the .html" method?
A file with a .html extension that contains php code in it somewhere.
Up until then
- my .html files contained only HTML plus the Apache SSI code.
- all of my PHP code was in files with .php extension
Well - I couldn't get the PHP code inside the .htm file to be actioned.
This sounds like the orginal problem - that your html file is not being php parsed.
You are correct in that the code was not being parsed - but this was not my original
problem because I did not have any PHP code inside any .html code until I made the test referred to above.
So perhaps I have hit the issue on my hoster of not being able to mix SSI and embedded PHP ...
I can't turn of the SSI as a whole because it will mess up other stuff that is already there ... so I had to dig harder.
You don't need (probably) to turn SSI off, but you don't need to use it, either. I suppose it's possible to just SSI #include a php script you write, that makes the appropriate includes of the guest book script, setting the parameters appropriately, but you need to understand enough about how the script works to do this.
The SSI functionality as a whole is enabled by a setting in the .htaccess file.
The suggestion from other threads in this forum is that enabling it at all (i.e. in the .htaccess file) will sometimes prevent Apache from parsing PHP code inside .html files. I appear to have that problem.
At this stage I can't risk turning the facility off (by editing the .htaccess file) because other web pages on the site are successfully using SSI to invoke PHP (e.g. the Now Playing part on the main page). I could experiment on another site or perhaps in a lower level subdirectory - but that might have to wait for another day.
I found that _SERVER["REDIRECT_QUERY_STRING"] does contain the query string that the .htm was called with
i.e. the php that I call via the SSI #include can see the original query.
So I am now writing a quick hack to parse that and I think I'll be OK.
I updated the demo.htm on my site to show it in action.
The best test is to SSI #include a test.php that includes just
It was doing something like that that let me finally find the _SERVER["REDIRECT_QUERY_STRING"] field.
Good luck anyway.
Thanks. I realise that all of this quoting makes it a bit difficult to work out what has been going on - but I thought that I should post back just in case anyone else ever hits something like this.
To whoever hits on this thread in the future ... I suggest reading slowly with a long cool drink