2012-10-05 6 views
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

당신은 정말 매개 변수화 된 쿼리를 사용한다 PDO하는 것이 좋습니다됩니다 감사하겠습니다 : http://stackoverflow.com/questions/ 60174/best-way-to-prevent-sql-injection-in-php –

+0

PHP는 mysql_ questions와 관련하여 PDO 사용에 관한 게시물을 자동화해야합니다. – ficuscr

+0

해당 링크 고마워요. @JordanKaye – Octavius

답변

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); 
} 

난 당신이 prepared statement

$q=$pdo->prepare("query where id=:id"); 
$q->execute(array(":id"=>1)) 
+0

johonraymos에 모욕감이 없습니다. 하지만 그 코드를 사용하기 전에 PHP를 업그레이드 할 것입니다. 나는 그것이 항상 완벽한 세상은 아니라는 것을 알고 있습니다. – ficuscr

+0

업그레이드에 대해 어떻게 생각 하시나요? 그 이유는 무엇입니까? @ ficuscr – Octavius

+1

그냥 말해. PHP 4.3은 2002 년에 출시되었습니다. 일반적으로 지원되지 않는 것들과 10 년 이상 된 것들을 코딩하지 않습니다. – ficuscr