<?
//########################################################################################
// -------------- Summary
// V1.0
// Setting register_globals=On in php.ini automatically fills variables like
// $userName with $HTTP_GET_VARS["username"], and so on. As it represents a major security issue,
// its default value is Off from PHP4.2. To deal with this, reGlobals allows :
// Phase 1 - To make all pages that needs register_globals=on to work on a server with register_globals=off
// Phase 2 - Modifies automatically page source code to include $userName=$HTTP_GET_VARS["username"]-like statments
// so reGlobals() class can also be removed and the page is completely secure.
//
// See http://fr.php.net/manual/fr/configuration.directives.php#ini.register-globals
// or http://fr.php.net/manual/en/configuration.directives.php#ini.register-globals
// for the risks of using register_globals=On
//
// -------------- Author
// Logan Dugenoux - 2004
// hide@address.com
// http://www.peous.com/logan/
//
// -------------- License
// LGPL
//
// -------------- Methods :
// - reGlobals( bool modify_sourcecode=false )
//
// ------------- Example :
// new reGlobals();
// echo $value_of_any_post_var;
// echo $value_of_any_get_var_also;
//
//
// -------------
// Have fun !!!
//
//########################################################################################
<?
class reGlobals
{
function reGlobals( $printInFile = false )
{
global $HTTP_GET_VARS;
global $HTTP_POST_VARS;
global $HTTP_SERVER_VARS;
foreach( $HTTP_GET_VARS as $k => $v )
{
$GLOBALS[$k] = $v;
}
foreach( $HTTP_POST_VARS as $k => $v )
{
$GLOBALS[$k] = $v;
}
$tOut = "";
@$exData = implode("", file($HTTP_SERVER_VARS['SCRIPT_FILENAME']) );
foreach( $HTTP_GET_VARS as $k => $v )
{
if (!strstr($exData, "\$HTTP_GET_VARS['".$k."']"))
{
$txt = "\$".$k." =";
while (strlen($txt)<16) $txt .= " ";
$txt .= "\$HTTP_GET_VARS['".$k."'];";
while (strlen($txt)<50) $txt .= " ";
if (is_array($v))
{
$txt .= "// array. \n";
}
else
{
$txt .= "// ex. '".str_replace("\n", "", substr($v,0,20))."'\n";
}
$tOut .= $txt;
}
}
foreach( $HTTP_POST_VARS as $k => $v )
{
if (!strstr($exData, "\$HTTP_POST_VARS['".$k."']"))
{
$txt = "\$".$k." =";
while (strlen($txt)<16) $txt .= " ";
$txt .= "\$HTTP_POST_VARS['".$k."'];";
while (strlen($txt)<50) $txt .= " ";
if (is_array($v))
{
$txt .= "// array. \n";
}
else
{
$txt .= "// ex. '".str_replace("\n", "", substr($v,0,20))."'\n";
}
$tOut .= $txt;
}
}
if ($printInFile)
{
if ($tOut)
{
$f = fopen( $HTTP_SERVER_VARS['SCRIPT_FILENAME'], "w" );
fwrite($f, "<? //--------------------------------" );
fwrite($f, " // auto-generated on the ".date("j/m/Y"));
if ($HTTP_SERVER_VARS['HTTP_REFERER'])
fwrite($f,", referer ".$HTTP_SERVER_VARS['HTTP_REFERER'] );
fwrite($f,"\n" );
fwrite($f, $tOut );
fwrite($f, "?>\n" );
fwrite($f, $exData );
}
fclose( $f );
}
}
}
?>