Here's an utterly insane way of fixing globals:
<?
function fix_globals($errno, $errstr, $errfile, $errline) {
$code = file($errfile);
$line = $code[$errline - 1];
if(preg_match('/Undefined variable:\s+(\w+)/', $errstr, $matches)) {
$varname =$matches[1];
if(array_key_exists($varname, $_GET)) {
$new_line = preg_replace("/\\\$$varname/", "\$_GET['$varname']", $line);
}
else if(array_key_exists($varname, $_POST)) {
$new_line = preg_replace("/\\\$$varname(?!\w)/", "\$_POST['$varname']",
$line);
}
else if(array_key_exists($varname, $_SERVER)) {
$new_line = preg_replace("/\\\$$varname(?!\w)/", "\$_SERVER['$varname']",
$line);
}
}
if($new_line) {
$code[$errline - 1] = $new_line;
if($f = fopen($errfile, "w")) {
fwrite($f, implode('', $code));
fclose($f);
header("HTTP/1.0 307 Temporary Redirect");
header("Location:
http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}");
exit(0);
}
}
}
ob_start();
set_error_handler('fix_globals');
.....
?>
Yup, the code fixes itself!
Uzytkownik "News" <ne**@news.com> napisal w wiadomosci
news:10*************@corp.supernews.com...
All,
I have some code that works just fine when register_globals is on,
however, for obvious reasons, I am trying to rework the code so that I can disable
register_globals.
I have set my error_reporting to E_ALL, and am logging it to a file so
that I can review it.
Are there any "steps" to take in successfully updating the code ? Or do I
just run each and every page looking for errors ?
Any pointers would be appreciated.
Thanks.