Module 3

Session Management, Cookies & Web Security

25 mins read

Lesson 1: PHP Forms & Security

1.1 Handling HTML Forms & CSRF

Handling `$_POST` form data, sanitizing input with `htmlspecialchars()`, and implementing CSRF token protection.

PHP
<?php
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $username = htmlspecialchars($_POST['username']);
    $_SESSION['dbusername'] = $username;
}
?>