What would cause PHP variables to be rewritten by the server?

前端 未结 1 511
小鲜肉
小鲜肉 2021-02-20 13:55

I was given a VM at my company to install web software on. But I came across a rather bizarre issue where PHP variables would be overwritten (rewritten) by the server if they ma

相关标签:
1条回答
  • 2021-02-20 14:27

    Output overwriting is possible within Apache by using mod_perl: PerlOutputFilterHandler.

    The following could be added to an apache.conf to set the output filter:

    <FilesMatch "\.(html?|php|xml|css)$">
        PerlSetVar Filter On
        PerlHandler MyApache2::FilterDomain
        PerlOutputFilterHandler MyApache2::FilterDomain
    </FilesMatch>
    

    Example filter handler code:

    #file:MyApache2/FilterDomain.pm
    #--------------------------------
    package MyApache2::FilterDomain;
    
    use strict;
    use warnings;
    
    use Apache2::Filter();
    use Apache2::RequestRec();
    use APR::Table();
    
    use Apache2::Const -compile => qw(OK);
    
    use constant BUFF_LEN => 1024;
    
    sub handler {
        my $f = shift;
        my @hostname = split(/\./, $f->r->hostname);
        my $new_hostname = $hostname[0].".".$hostname[1];
    
        unless ($f->ctx) {
            $f->r->headers_out->unset('Content-Length');
            $f->ctx(1);
        }
    
        while ($f->read(my $buffer, BUFF_LEN)) {
            $buffer =~ s/([a-z0-9]+)+\.domain\./$new_hostname\.$1.domain\./g;   
            $f->print($buffer);
        }
    
        return Apache2::Const::OK;
    }
    1;
    

    More on Apache mod_perl filters can be found here: mod_perl: Input and Output Filters

    0 讨论(0)
提交回复
热议问题