什么会导致PHP变量由服务器改写? [英] What would cause PHP variables to be rewritten by the server?
问题描述
我在我公司安装网络软件给出一个虚拟机。但是,我遇到了一个相当奇特的问题,即PHP变量将由服务器,如果他们匹配特定的模式覆盖(重写)。什么可以重写PHP变量这样?
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 matched a specific pattern. What could rewrite PHP variables like this?
下面是作为一个完整独立的脚本。
The following is as an entire standalone script.
<?php
$foo = 'b.domain.com';
echo $foo; // 'dev01.sandbox.b.domain.com'
$bar = 'dev01.sandbox.domain.com';
echo $bar; // 'dev01.sandbox.sandbox.domain.com'
$var = 'b.domainfoo.com';
echo $var; // 'b.domainfoo.com' (not overwritten because it didn't match whatever RegEx has been set)
?>
从本质上讲它包含一个子域和域名匹配的任何变量将被改写。这不是mod_rewrite的将能够触及,所以它必须是在服务器级别的东西是解析出PHP和重写一个字符串,如果它正则表达式匹配。
Essentially any variable which contains a subdomain and matches on the domain name would be rewritten. This isn't something mod_rewrite would be able to touch, so it has to be something at the server level that is parsing out PHP and rewriting a string if it matches a RegEx.
推荐答案
输出改写可能范围内的Apache使用的mod_perl:PerlOutputFilterHandler
Output overwriting is possible within Apache by using mod_perl: PerlOutputFilterHandler.
以下可以被添加到的apache.conf设置输出滤波器:
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>
例过滤处理code:
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;
更多关于Apache mod_perl的过滤器可以在这里找到:的mod_perl:输入和输出滤波器
这篇关于什么会导致PHP变量由服务器改写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!