Forum Moderators: coopster

Message Too Old, No Replies

parsing htm files as php from within a php file

...using AddHandler in .htaccess (Apache)

         

dhiggerdhigger

8:59 am on Apr 1, 2004 (gmt 0)

10+ Year Member



This is in the right forum, honest.

I am compressing the .htm files served from a website using these lines in my (Apache) htaccess:

AddHandler compress .htm
Action compress /php/compress.php
The compress.php file is simple (described here [ideamarketers.com]):

<?php
ob_start("ob_gzhandler");
$file = $_SERVER["PATH_TRANSLATED"];
readfile($file);
?>

Before I implemented this php compression, I had the server parse .htm files as php using

AddType application/x-httpd-php .htm
in htaccess. But now that the Handler is functioning (and it works great), embedded php in my .htm files is no longer executed. It seems the server may be parsing the files as php after the Handler does the compression. One solution might be to force the server to do the compression last, and parse the .htm files as php first. (I am looking into how to get Apache to do this.) But here's a thought:

Can I get the server to parse the .htm file as php from within the compress.php file, which the Handler uses?

Thanks
Dave Higgins

PS. Server: Apache/1.3.22 (Unix) PHP/4.3.4 mod_perl/1.26
I am using the zlib module for compression because mod_gzip is not installed.

mykel79

10:23 am on Apr 1, 2004 (gmt 0)

10+ Year Member



Have you tried using include() (which pareses the file) instead of readfile()?

dhiggerdhigger

11:15 am on Apr 1, 2004 (gmt 0)

10+ Year Member



I just tried
include()
instead of
readfile()
.

With

readfile()
, the
<?php ...whatever...?>
is simply displayed as text in the page source from the browser.
With
include()
, the embedded php completely disappears! The php code is not being executed (part of the php code inserts a comment back into the html saying, in effect, "everything worked ok").

So it seems that

include()
doesn't do the job. (Unless there's other code to modify what
include()
does?)

Any other ideas?
Thanks
Dave Higgins

dhiggerdhigger

4:54 pm on Apr 1, 2004 (gmt 0)

10+ Year Member



I have a workaround. (It only took all day to find out about...)

I now have this in my .htaccess, instead of the AddHandler and Action lines:

php_value auto_prepend_file "/usr/home/dmh/WWW/mri/php/compress.php"

And the compress.php file is just

<?php
ob_start("ob_gzhandler");
?>

I think that now, if the server parses anything as php, it simply adds this line to the start of the file before it does the parsing. The compression works, anyhow, and my.htm files are parsed as php again.

Dave Higgins