SQL Injection

$txtUserId = $_GET("UserId");
$txtSQL = "SELECT * FROM Users WHERE UserId = " . $txtUserId;
SELECT * FROM Users WHERE UserId = 105; DROP TABLE Suppliers;

방어법

$stmt = $dbh->prepare("INSERT INTO Customers (CustomerName,Address,City)
VALUES (:nam, :add, :cit)");
$stmt->bindParam(':nam', $txtNam);
$stmt->bindParam(':add', $txtAdd);
$stmt->bindParam(':cit', $txtCit);
$stmt->execute();
//$sql = "SELECT * FROM SQL_Injection WHERE type='".$_GET['type']."'";
$sql = "SELECT * FROM SQL_Injection WHERE type='".mysql_real_escape_string($_GET['type'])."'";
SELECT * FROM SQL_Injection WHERE type='public\' or 1=\'1'

ref

What Else?
inflearn react api server -50% 할인쿠폰: 20652-ab1f1cd4c373 buy me a coffee