470,848 Members | 1,817 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

Register_globals ON --> OFF

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.
Jul 17 '05 #1
1 1472
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.

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Christian Schmidbauer | last post: by
2 posts views Thread by Donald Firesmith | last post: by
34 posts views Thread by Mark Moore | last post: by
11 posts views Thread by Les Paul | last post: by
reply views Thread by vdex42 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.