为什么我的SSI行不通?

时间:2022-08-23 12:11:45

I am having problems with passing query params into SSI include from within my zend framework application.

我在将查询解析符从zend framework应用程序中传递到SSI include时遇到了问题。

I am trying to include a PHP file inside another PHP:

我正在尝试在另一个PHP中包含一个PHP文件:

<!--#include virtual='/ssi/test.php?x=hello' -->

This executes properly, if my hellotest.php (which contains the above line) resides in my document root.

如果我的hellotest,这将正确执行。php(包含上面一行)驻留在我的文档根目录中。

If, however I do the same thing from within my template.phtml (not /public_html/hellotest.php anymore) (I am using Zend Framework for this project) , the test.php is called and executed without any query parameters (in this case x=hello). No query parameters are passed into test.php from withitn my zend_framework templates .

但是,如果我在模板中做同样的事情。phtml(不是/ public_html / hellotest。(我正在为这个项目使用Zend框架),测试。调用和执行php时不需要任何查询参数(在本例中x=hello)。没有将查询参数传递给测试。php来自我的zend_framework模板。

Does this have anything to do with the way zend framework uses .htaccess ? Here is a copy of my .htaccess files (in web root: /public_html/.htaccess)

这与zend framework使用.htaccess的方式有什么关系吗?这里是我的.htaccess文件的副本(在web root中:/public_html/.htaccess)



SetEnv APPLICATION_ENV development

AddOutputFilter INCLUDES .php

RewriteEngine On

RewriteRule (.*/?)(.*css)$ combine.php?type=css&files=$1$2 [NC,L]
RewriteRule (.*/?)(.*js)$ combine.php?type=js&files=$1$2 [NC,L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

EDIT: I've recently found out, that it will pass parameters into the SSI taken from URL . So if in my browser I type http://www.test.com/controller/action?param1=something , it will actually pass param1 into the SSI , but it will totally ignore the params I have on the SSI line. ... anyone has experience with this ?

编辑:我最近发现,它将把参数传递给从URL获取的SSI。如果我在浏览器中输入http://www.test.com/controller/action?param1=某物,它实际上会把param1传给SSI,但它会完全忽略我在SSI线上的params。有人有这方面的经验吗?

EDIT2 - in response to Tim Fountain: correct, my test.php is at public_html/ssi/test.php .. However, I am calling from a ZF template file , which gets parsed by ZF always..not sure what you ment by "as long as it's not parsed by ZF" . In my test.php I simple output var_dump($_GET) - nothing else is in that php file, just that one line. And the way I call it from the ZF template file is like so: <!--#include virtual='/ssi/test.php?x=hello' -->

回应蒂姆·喷泉:正确,我的测试。php在public_html / ssi /测试。php . .但是,我是从ZF模板文件调用的,ZF总是解析这个模板文件。不确定你用“只要不被ZF解析”来表示什么。在我的测试。php I简单的输出var_dump($_GET)—php文件中没有其他内容,只有一行。我从ZF模板文件中调用它的方式是:

. the strange thing is, that if I type http://mydomain.com/controller/action/?x=hi_there , it will actually pass that X param to my SSI include line , and will overwrite whatever I had there originally (x=hello) . If I don't pass anything in the URL, nothing will get passed to SSI.

。奇怪的是,如果我输入http://dommy.com/controller/action/?x=hi_there,它实际上会将x参数传递给我的SSI include行,并覆盖我最初在那里的内容(x=hello)。如果我在URL中没有传递任何东西,就没有什么会被传递给SSI。

2 个解决方案

#1


2  

Instead of using the SSI include, you could try using the php virtual function:

您可以尝试使用php虚拟函数,而不是使用SSI include:

virtual ("/ssi/test.php?x=hello");

via http://www.zytrax.com/tech/php/php_ssi.htm

通过http://www.zytrax.com/tech/php/php_ssi.htm

What kind of caching requires you to use SSI? Couldn't you just use something like Zend_Cache_Frontend_Output?

需要使用哪种缓存?难道你不能使用Zend_Cache_Frontend_Output这样的函数吗?

#2


1  

I've never seen SSI used with PHP in this way so this is something of a long shot, but can you try changing:

我从来没有见过SSI以这种方式与PHP结合,所以这是一个很长的尝试,但是你能尝试改变吗:

AddOutputFilter INCLUDES .php

to:

:

AddOutputFilterByType INCLUDES text/html

the reason it's not working is that your files no longer have a .php extension (or any extension), since you're routing everything through index.php. The change I've suggested will filter all text/html output (which should include PHP) though the SSI parser, instead of doing so by extension.

它不能工作的原因是您的文件不再有.php扩展名(或任何扩展名),因为您正在通过index.php路由所有内容。我建议的更改将通过SSI解析器过滤所有文本/html输出(应该包括PHP),而不是通过扩展来过滤。

#1


2  

Instead of using the SSI include, you could try using the php virtual function:

您可以尝试使用php虚拟函数,而不是使用SSI include:

virtual ("/ssi/test.php?x=hello");

via http://www.zytrax.com/tech/php/php_ssi.htm

通过http://www.zytrax.com/tech/php/php_ssi.htm

What kind of caching requires you to use SSI? Couldn't you just use something like Zend_Cache_Frontend_Output?

需要使用哪种缓存?难道你不能使用Zend_Cache_Frontend_Output这样的函数吗?

#2


1  

I've never seen SSI used with PHP in this way so this is something of a long shot, but can you try changing:

我从来没有见过SSI以这种方式与PHP结合,所以这是一个很长的尝试,但是你能尝试改变吗:

AddOutputFilter INCLUDES .php

to:

:

AddOutputFilterByType INCLUDES text/html

the reason it's not working is that your files no longer have a .php extension (or any extension), since you're routing everything through index.php. The change I've suggested will filter all text/html output (which should include PHP) though the SSI parser, instead of doing so by extension.

它不能工作的原因是您的文件不再有.php扩展名(或任何扩展名),因为您正在通过index.php路由所有内容。我建议的更改将通过SSI解析器过滤所有文本/html输出(应该包括PHP),而不是通过扩展来过滤。