You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Omer Shenker <ma...@omershenker.net> on 2003/06/01 03:49:28 UTC

[users@httpd] Problems using PHP filters with mod_cgi

Hello,

I'm running 2.0.46 on Mandrake 9.1, and using mod_php 4.3.1. The exact
server string is:
Apache-AdvancedExtranetServer/2.0.46 (Mandrake Linux/4.2mdk) mod_ssl/2.0.46
OpenSSL/0.9.7a PHP/4.3.1
It's from the Mandrake RPMs.

I have a bunch of Perl scripts with .cgi extensions that output PHP, which
I'd like to be processed by the PHP filter before being sent to the browser.
(Don't ask why I have to get this working; there are some things in life you
sleep better not knowing.) Here's what I believe to be the relevant lines in
the config files, from inside a <VirtualHost>:

AddOutputFilter PHP .cgi   # line 1
AddInputFilter PHP .cgi    # line 2
AddHandler cgi-script .cgi # line 3

Just for testing, I created test.cgi, the contents of which are:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "foo";
print "<?php print 'bar';?>";
#EOF

With none of the lines (or just line 2) I get the source of the file.

With line 1 or lines 1 and 2, I get the source but the last line is just
'print "bar";' because the PHP has evaluated.

With line 3, lines 1 and 3, lines 2 and 3, or all three lines I get
"foo<?php print 'bar';?>".

Of course, what I really want is "foobar". :)

If anyone has any ideas, I'd be very grateful. If I can't get it working
nicely like this I'll probably end up writing an external handler that runs
the files through perl, then sends them to php with the environment and
stdin again (because php also needs the CGI params), which means spawning a
triplet of processes for each request.

-- 
Omer Shenker                          http://omershenker.net/



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Re: Problems using PHP filters with mod_cgi

Posted by WC -Sx- Jones <li...@insecurity.org>.
On Sunday, June 1, 2003, at 10:51  AM, Omer Shenker wrote:

> ExtFilterDefine phpfilter cmd=/usr/bin/php mode=output
> ftype=AP_FTYPE_CONTENT_SET
> ...
> AddHandler cgi-script .cgi
> AddOutputFilter phpfilter .cgi
>
> This does indeed give me foobar (at last!), but it's a very inefficient
> kludge.


Well, you are make TWO different scripting langauges work "closer" 
together  :)


I think I almost have AddOutputFilter working -- if I do I will post 
the results...

-Sx-


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Re: Problems using PHP filters with mod_cgi

Posted by Omer Shenker <ma...@omershenker.net>.
I think I've found a solution, though it's less than optimal.

ExtFilterDefine phpfilter cmd=/usr/bin/php mode=output
ftype=AP_FTYPE_CONTENT_SET
...
AddHandler cgi-script .cgi
AddOutputFilter phpfilter .cgi

This does indeed give me foobar (at last!), but it's a very inefficient
kludge.

[Aside: I think there's a bug. When you use AddOutputFilter on an external
filter, the filtername will be converted to lowercase. However,
ExtFilterDefine preserves case.]

-- 
Omer Shenker                          http://omershenker.net/



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Re: Problems using PHP filters with mod_cgi

Posted by Rich Bowen <rb...@rcbowen.com>.
On Sun, 1 Jun 2003, Omer Shenker wrote:

> On Saturday 31 May 2003 at 21:54 WC -Sx- Jones wrote:
> > You sure you don't get "bar"  --  I mean that should be what
> > is printed
> > IF php was eval'ing like you state...
>
> Yeah, I'm sure. The PHP evals but then the Perl doesn't. Or vice versa,
> depending on the configuration. But I can't get them both to eval for the
> same request--and the Perl needs to eval first anyway.

You don't need the InputFilter, if I understand you correctly. You just
need the AddHandler and the AddOutputFilter. The names mean what they
say, and you are not filtering any input. (Input is what comes in from
the client.) However, I don't expect that this is the source of your
problem. I know that the following works:

AddHandler cgi-script .cgi
AddOutputFilter INCLUDES .cgi

However, I don't have PHP installed right now to test the analogous PHP
configuration.

-- 
Rich Bowen - rbowen@rcbowen.com
... and another brother out of his mind, and another brother out at New
York (not the same, though it might appear so)
	Somebody's Luggage (Charles Dickens)

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Re: Problems using PHP filters with mod_cgi

Posted by Omer Shenker <ma...@omershenker.net>.
On Saturday 31 May 2003 at 21:54 WC -Sx- Jones wrote:
> You sure you don't get "bar"  --  I mean that should be what 
> is printed 
> IF php was eval'ing like you state...

Yeah, I'm sure. The PHP evals but then the Perl doesn't. Or vice versa,
depending on the configuration. But I can't get them both to eval for the
same request--and the Perl needs to eval first anyway.

-- 
Omer Shenker                          http://omershenker.net/



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Problems using PHP filters with mod_cgi

Posted by WC -Sx- Jones <li...@insecurity.org>.
On Saturday, May 31, 2003, at 09:49  PM, Omer Shenker wrote:
> print "<?php print 'bar';?>";

You sure you don't get "bar"  --  I mean that should be what is printed 
IF php was eval'ing like you state...


???/Sx ???

http://InSecurity.org/
_Sx____________________
  ('>    iudicium ferat
  //\   Have Computer -
  v_/_    Will Hack...

               \|/ ____ \|/
               "@'/ .. \`@"
               /_| \__/ |_\
                  \__U_/


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Problems using PHP filters with mod_cgi

Posted by WC -Sx- Jones <li...@insecurity.org>.
On Saturday, May 31, 2003, at 09:49  PM, Omer Shenker wrote:

> AddOutputFilter


I think you would only want to set AddOutputFilter - the others maybe 
resetting it back to Perl.

???/Sx ?

http://InSecurity.org/
_Sx____________________
  ('>    iudicium ferat
  //\   Have Computer -
  v_/_    Will Hack...

               \|/ ____ \|/
               "@'/ .. \`@"
               /_| \__/ |_\
                  \__U_/


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org