2012-07-08 3 views
2

가능한 중복 :
Best way to prevent SQL Injection in PHPpdo 보안을 위해 일반 sql PHP 코드를 변경하는 방법은 무엇입니까?

는 PDO로 변경 할 필요가 있는가 내가 mysql_real_escape_string를 사용하고 있기 때문에이 코드 안전하며 strip_tags? 다음 코드를 헤더를 수정할 수 없으므로 pdo로 변환 할 수 없습니다.

<?php 
include('config.php'); 
$link =mysql_connect($db_host,$username,$password); 
mysql_select_db($db_name); 

$id= $_POST["uniqi"]; 
$comments= $_POST["comments"]; 
$comments= mysql_real_escape_string($comments); 
$comments = strip_tags($comments); 

$update = "UPDATE mastertable SET comments = '$comments' WHERE id_pk= '$id'"; 
mysql_query($update, $link); 
mysql_close(); 
header('Location: http://www.xxxx.com/xxxxx/xxxx.php?cntmsg=Comment Updated'); 
?> 
+1

당신은 확실히 PDO로 변환해야합니다 - mysql 확장 기능은 (http://news.php.net/php.internals/53799) 사용되지 않습니다. – DCoder

+0

http://stackoverflow.com/questions/8028957/headers-already-sent-by-php – PeeHaa

답변

1

이것은 안전 코드가 아닙니다. $id 변수가 코드에 의해 처리되지 않습니다.

$id= $_POST["uniqi"]; 
$id= mysql_real_escape_string($id); 
$id = strip_tags($id); 
+0

@vascowhite - 답장의 첫 부분은 코드 안전에 관한 실제입니다. –

+0

@TudorConstantin $ id가 업데이트 구문에 사용되었습니다. – Tom

+0

@Tom - 그렇습니다. 그러나 클라이언트 (브라우저)에서 오는 값을 사용합니다. - ''와 같이 드래곤을 보낼 수 있습니다. 코멘트에서 삭제하십시오; SELECT '대신에 ID : –

관련 문제