Register_globals ON --> OFF

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • News

    Register_globals ON --> OFF

    All,
    I have some code that works just fine when register_global s is on, however,
    for obvious reasons, I am trying to rework the code so that I can disable
    register_global s.

    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.


  • Chung Leong

    #2
    Re: Register_global s ON --> OFF

    Here's an utterly insane way of fixing globals:

    <?

    function fix_globals($er rno, $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_ex ists($varname, $_GET)) {
    $new_line = preg_replace("/\\\$$varname/", "\$_GET['$varname']", $line);
    }
    else if(array_key_ex ists($varname, $_POST)) {
    $new_line = preg_replace("/\\\$$varname(?! \w)/", "\$_POST['$varname']",
    $line);
    }
    else if(array_key_ex ists($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("Locatio n:
    http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}");
    exit(0);
    }
    }
    }

    ob_start();
    set_error_handl er('fix_globals ');

    .....

    ?>

    Yup, the code fixes itself!

    Uzytkownik "News" <news@news.co m> napisal w wiadomosci
    news:1047i3jtfs e0v0d@corp.supe rnews.com...[color=blue]
    > All,
    > I have some code that works just fine when register_global s is on,[/color]
    however,[color=blue]
    > for obvious reasons, I am trying to rework the code so that I can disable
    > register_global s.
    >
    > I have set my error_reporting to E_ALL, and am logging it to a file so[/color]
    that[color=blue]
    > 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.
    >
    >[/color]


    Comment

    Working...