Backend
Web Security 101: ป้องกันเว็บจากการโจมตีที่พบบ่อยที่สุด
สมชาย ใจดี
2026-06-14
1. SQL Injection
ผู้โจมตีแทรก SQL code เข้าไปใน input เพื่อดึง/แก้ไข/ลบข้อมูล
// Safe - Parameterized Query
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?");
$stmt->execute([$username]);
2. Cross-Site Scripting (XSS)
// Safe - Escape output
echo htmlspecialchars($_GET["name"], ENT_QUOTES, "UTF-8");
3. Password Security
$hash = password_hash($password, PASSWORD_BCRYPT, ["cost" => 12]);
$valid = password_verify($password, $hash);
| รายการ | สถานะ |
|---|---|
| ใช้ Parameterized Query | ต้องทำ |
| Escape output | ต้องทำ |
| CSRF Token ทุก form | ต้องทำ |
| bcrypt สำหรับ password | ต้องทำ |