Launch Offer! Use code HOSGELDIN10 for an instant 10% extra discount on all software!
Web Tasarım
Security 26.11.2026 2 min read 377 views

Web Application Security A–Z: SQL Injection, XSS, CSRF, Bcrypt & License Protection

Multi-layer OWASP defense in modern PHP: native PDO prepared statements, CSRF tokens, strict XSS escaping, brute-force rate limiting, and HMAC-SHA256 license guards.

Web Application Security A–Z: SQL Injection, XSS, CSRF, Bcrypt & License Protection

Security Is an Architectural Foundation, Not an Afterthought

A breached website costs far more than downtime—it leads to Google Safe Browsing blacklisting, lost customer trust, and serious GDPR/KVKK legal exposure. Every layer must be hardened from day one.

1. Eliminating SQL Injection Permanently

Never concatenate $_GET or $_POST inputs into SQL strings. Always use native PDO Prepared Statements with ATTR_EMULATE_PREPARES => false.

2. Strict XSS (Cross-Site Scripting) Escaping

Every dynamic value rendered into HTML should pass through a centralized UTF-8 escape helper:

php
function e(?string $value): string {
    return htmlspecialchars((string)$value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}

3. Timing-Safe CSRF Validation

Every admin, checkout, cart, and account POST form must carry a cryptographically random token verified via hash_equals():

php
function csrf_token(): string {
    if (empty($_SESSION['csrf_token'])) {
        $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
    }
    return $_SESSION['csrf_token'];
}

function verify_csrf(?string $token): bool {
    return !empty($_SESSION['csrf_token'])
        && is_string($token)
        && hash_equals($_SESSION['csrf_token'], $token);
}

4. Password Hashing, Rate Limiting & Hardened Headers

  • Bcrypt / Argon2id (password_hash): Never store plain text or legacy MD5/SHA1 hashes.
  • Brute-Force Rate Limiting: Lock abusive IPs automatically after failed login bursts and log every attempt.
  • Security Headers: Enforce X-Content-Type-Options: nosniff, X-Frame-Options: SAMEORIGIN, and Referrer-Policy at the web server level.
  • Protected Downloads: Block direct web access to .sql, .env, .log, and /downloads/; stream archives exclusively through authenticated license checks.

5. Zero-Trust HMAC-SHA256 License Verification

To protect commercial PHP products from piracy, domain + license pairs are signed server-side using hash_hmac('sha256', ...) and validated with constant-time hash_equals().

Real security never relies on a single wall—it combines database, session, filesystem, and HTTP header hardening in depth.
Written by Aköz Web Tasarım

More Guides & Notes

All Articles
Added to cart.