0

データベース攻撃を防ぐために get_magic_quotes_gpc を使用することはまだ適切ですか? 魔法の引用符が有効になっている場合は、余分なスラッシュを取り除きたいと思いました。

if(get_magic_quotes_gpc()){
    If magic quotes is enabled, strip the extra slashes
    array_walk_recursive($_GET,create_function('&$v,$k','$v = stripslashes($v);'));
    array_walk_recursive($_POST,create_function('&$v,$k','$v = stripslashes($v);'));
}

PHPのマニュアルを見たところ、廃止されていることがわかりました。どの代替手段を使用できるか、または私が気付いていない微調整があるかどうかはわかりません。私はまだプログラミングやさまざまなコーディング手法の学習に慣れていません。どんなヒントでも大歓迎です

4

1 に答える 1

1

これを使って

function mysql_prep($value)
{
    $magic_quotes_active = get_magic_quotes_gpc();
    $new_enough_php = function_exists("mysql_real_escape_string");
    if ($new_enough_php) { 
        // undo any magic quote effects so mysql_real_escape_string can do the work
        if ($magic_quotes_active) {
            $value = stripslashes($value);
        }
        $value = mysql_real_escape_string($value);
    } else { 
        // if magic quotes aren't already on then add slashes manually
        if (!$magic_quotes_active) {
            $value = addslashes($value);
        }
        // if magic quotes are active, then the slashes already exist
    }
    return ($value);
}

私はあなたにpdoをお勧めしますprepared statement

$q=$pdo->prepare("query where id=:id");
$q->execute(array(":id"=>1))
于 2012-10-05T17:54:30.200 に答える