$m2) {
global $$m1;
$$m1 = ${$ch}[$m1];
}
//if (@count($$ch) > 0) {
// extract($$ch, EXTR_OVERWRITE);
//}
}
}
} else {
// if (ini_get_bool('register_globals') == '1') {
if ($VCO_REGISTER_GLBOALS) {
X_debug('Emulate register_globals=off (is on)');
// This is NOT possible with PHP
// ini_set('register_globals', 0);
foreach ($types_to_register as $rtype) {
$ch = '_'.$rtype;
global $$ch; // Bug in PHP?
foreach ($$ch AS $m1 => $m2) {
global $$m1;
$$m1 = null;
}
}
}
}
}
# -----------------------------------------------------------------------------
# REGISTER LONG ARRAYS (STABLE)
# -----------------------------------------------------------------------------
$VCO_REGISTER_LONG_ARRAY = ini_get_bool('register_long_arrays');
function emulate_register_long_arrays($onoff) {
global $types_to_register;
global $VCO_REGISTER_LONG_ARRAY;
if ($onoff) {
// if (ini_get_bool('register_long_arrays') != '1') {
if (!$VCO_REGISTER_LONG_ARRAY) {
X_debug('Emulate register_long_arrays=on (is off)');
ini_set('register_long_arrays', 1); # todo: geht das?
foreach ($types_to_register as $rtype) {
$ch1 = 'HTTP_'.$rtype.'_VARS';
$ch2 = '_'.$rtype;
global $$ch2; // Bug in PHP? Ist doch superglobal!
global $$ch1;
$$ch1 = array();
foreach ($$ch2 AS $m1 => $m2) {
${$ch1}[$m1] = ${$ch2}[$m1];
}
}
}
} else {
// if (ini_get_bool('register_long_arrays') == '1') {
if ($VCO_REGISTER_LONG_ARRAY) {
X_debug('Emulate register_long_arrays=off (is on)');
ini_set('register_long_arrays', 0); # todo: geht das?
foreach ($types_to_register as $rtype) {
$ch1 = 'HTTP_'.$rtype.'_VARS';
$ch2 = '_'.$rtype;
global $$ch2; // Bug in PHP? Ist doch superglobal!
global $$ch1;
foreach ($$ch2 AS $m1 => $m2) {
if (isset(${$ch1}[$m1])) {
${$ch1}[$m1] = null;
}
}
$$ch1 = null;
}
}
}
}
# -----------------------------------------------------------------------------
# MAGIC QUOTES GPC (WIP)
# -----------------------------------------------------------------------------
$VCO_EMULATED_GPC = ini_get_bool('magic_quotes_gpc');
function emulate_magic_quotes_gpc($onoff) {
global $types_to_register;
global $VCO_EMULATED_GPC;
/*
See: http://www.php.net/manual/en/info.configuration.php#ini.magic-quotes-gpc
TODO: In PHP 4, also $_ENV variables are escaped.
TODO: If the magic_quotes_sybase directive is also ON it will completely override magic_quotes_gpc. Having both directives enabled means only single quotes are escaped as ''. Double quotes, backslashes and NUL's will remain untouched and unescaped.
--> status speichern und dann ggf verstecktes magic_quotes_gpc aktivieren sobald magic_quotes_sybase deaktiviert wird
*/
if ($onoff) {
// if (ini_get_bool('magic_quotes_gpc') != '1') {
if (!$VCO_EMULATED_GPC) {
X_debug('Emulate magic_quotes_gpc=on (is off)');
ini_set('magic_quotes_gpc', 1); # todo: geht das?
foreach ($types_to_register as $rtype) {
if (($rtype != 'GET') && ($rtype != 'POST') && ($rtype != 'COOKIE')) continue;
$ch1 = 'HTTP_'.$rtype.'_VARS';
$ch2 = '_'.$rtype;
global $$ch2; // Bug in PHP? Ist doch superglobal!
global $$ch1;
foreach ($$ch2 AS $m1 => $m2) {
global $$m1;
global $VCO_EMULATED_SYBASE;
if (isset($$m1)) $$m1 = addslashes2($$m1, $VCO_EMULATED_SYBASE);
if (isset(${$ch1}[$m1])) ${$ch1}[$m1] = addslashes2(${$ch1}[$m1], $VCO_EMULATED_SYBASE);
if (isset(${$ch2}[$m1])) ${$ch2}[$m1] = addslashes2(${$ch2}[$m1], $VCO_EMULATED_SYBASE);
$_REQUEST[$m1] = addslashes2($_REQUEST[$m1], $VCO_EMULATED_SYBASE);
}
}
$VCO_EMULATED_GPC = 1;
}
} else {
// if (ini_get_bool('magic_quotes_gpc') == '1') {
if ($VCO_EMULATED_GPC) {
X_debug('Emulate magic_quotes_gpc=off (is on)');
ini_set('magic_quotes_gpc', 0); # todo: geht das?
foreach ($types_to_register as $rtype) {
if (($rtype != 'GET') && ($rtype != 'POST') && ($rtype != 'COOKIE')) continue;
$ch1 = 'HTTP_'.$rtype.'_VARS';
$ch2 = '_'.$rtype;
global $$ch2; // Bug in PHP? Ist doch superglobal!
global $$ch1;
foreach ($$ch2 AS $m1 => $m2) {
global $$m1;
global $VCO_EMULATED_SYBASE;
if (isset($$m1)) $$m1 = stripslashes2($$m1, $VCO_EMULATED_SYBASE);
if (isset(${$ch1}[$m1])) ${$ch1}[$m1] = stripslashes2(${$ch1}[$m1], $VCO_EMULATED_SYBASE);
if (isset(${$ch2}[$m1])) ${$ch2}[$m1] = stripslashes2(${$ch2}[$m1], $VCO_EMULATED_SYBASE);
$_REQUEST[$m1] = stripslashes2($_REQUEST[$m1], $VCO_EMULATED_SYBASE);
}
}
$VCO_EMULATED_GPC = 0;
}
}
}
# -----------------------------------------------------------------------------
# MAGIC QUOTES SYBASE (WIP)
# -----------------------------------------------------------------------------
$VCO_EMULATED_SYBASE = ini_get_bool('magic_quotes_sybase');
function emulate_magic_quotes_sybase($onoff) {
global $types_to_register;
global $VCO_EMULATED_SYBASE;
if ($onoff) {
// if (ini_get_bool('magic_quotes_sybase') != '1') {
if (!$VCO_EMULATED_SYBASE) {
X_debug('Emulate magic_quotes_sybase=on (is off)');
ini_set('magic_quotes_sybase', 1); # todo geht nicht???
global $VCO_EMULATED_GPC;
if ($VCO_EMULATED_GPC) {
foreach ($types_to_register as $rtype) {
if (($rtype != 'GET') && ($rtype != 'POST') && ($rtype != 'COOKIE')) continue;
$ch1 = 'HTTP_'.$rtype.'_VARS';
$ch2 = '_'.$rtype;
global $$ch2; // Bug in PHP? Ist doch superglobal!
global $$ch1;
foreach ($$ch2 AS $m1 => $m2) {
global $$m1;
global $VCO_EMULATED_SYBASE;
if (isset($$m1)) $$m1 = addslashes2(stripslashes2($$m1, $VCO_EMULATED_SYBASE), 1);
if (isset(${$ch1}[$m1])) ${$ch1}[$m1] = addslashes2(stripslashes2(${$ch1}[$m1], $VCO_EMULATED_SYBASE), 1);
if (isset(${$ch2}[$m1])) ${$ch2}[$m1] = addslashes2(stripslashes2(${$ch2}[$m1], $VCO_EMULATED_SYBASE), 1);
$_REQUEST[$m1] = addslashes2(stripslashes2($_REQUEST[$m1], $VCO_EMULATED_SYBASE), 1);
}
}
}
$VCO_EMULATED_SYBASE = 1;
}
} else {
// if (ini_get_bool('magic_quotes_sybase') == '1') {
if ($VCO_EMULATED_SYBASE) {
X_debug('Emulate magic_quotes_sybase=off (is on)');
ini_set('magic_quotes_sybase', 0); # todo geht nicht???
global $VCO_EMULATED_GPC;
if ($VCO_EMULATED_GPC) {
foreach ($types_to_register as $rtype) {
if (($rtype != 'GET') && ($rtype != 'POST') && ($rtype != 'COOKIE')) continue;
$ch1 = 'HTTP_'.$rtype.'_VARS';
$ch2 = '_'.$rtype;
global $$ch2; // Bug in PHP? Ist doch superglobal!
global $$ch1;
foreach ($$ch2 AS $m1 => $m2) {
global $$m1;
global $VCO_EMULATED_SYBASE;
if (isset($$m1)) $$m1 = addslashes2(stripslashes2($$m1, $VCO_EMULATED_SYBASE), 0);
if (isset(${$ch1}[$m1])) ${$ch1}[$m1] = addslashes2(stripslashes2(${$ch1}[$m1], $VCO_EMULATED_SYBASE), 0);
if (isset(${$ch2}[$m1])) ${$ch2}[$m1] = addslashes2(stripslashes2(${$ch2}[$m1], $VCO_EMULATED_SYBASE), 0);
$_REQUEST[$m1] = addslashes2(stripslashes2($_REQUEST[$m1], $VCO_EMULATED_SYBASE), 0);
}
}
}
$VCO_EMULATED_SYBASE = 0;
}
}
}
# ---
function addslashes2($cont, $sybase) {
if ($sybase) {
return str_replace("'", "''", $cont);
} else {
return addcslashes($cont, "\0\\\\'\"");
}
}
function stripslashes2($cont, $sybase) {
if ($sybase) {
return str_replace("''", "'", $cont);
} else {
return stripcslashes($cont);
}
}
function ini_get_bool($setting) {
$x = ini_initialvalue($setting);
if (strtolower($x) == 'off') $x = '0';
if (strtolower($x) == 'on') $x = '1';
return $x;
}
# Determinates the initial value of a setting without resetting it
# Important to detect how the GPC data is escaed since the user may call the emulation functions for magic_quotes_gpc and magic_quotes_sybase in different order!
function ini_initialvalue($setting) {
$bak = ini_get($setting);
ini_restore($setting);
$res = ini_get($setting);
ini_set($setting, $bak);
return $res;
}
# -----------------------------------------------------------------------------
# DEBUG
# -----------------------------------------------------------------------------
function X_debug($msg) {
if (defined('PHPCOMPAT_DEBUG') && PHPCOMPAT_DEBUG) {
echo "Debug: $msg
\n";
}
}
# MISC EMULATIONS
# geht nicht da __FILE__ sich aauf phpcompat.inc.phps bezieht
# if (!defined('__DIR__')) define('__DIR__', dirname(__FILE__)); // Magic constant introduced in PHP 5.3
?>