PHP htmlspecialchars to Prevent XSS (Tested Examples)
Prevent XSS in PHP by escaping output with htmlspecialchars(ENT_QUOTES, UTF-8): reflected XSS demo, sticky forms, attributes, and the cases it does not cover.
Notes
Security notes, SOC lab write-ups and tested code by Mahir Faysal, a SOC Level 1 cybersecurity learner in Bangladesh, plus notes from my Next.js and Gemini projects. Sample posts are marked and drafts stay in the admin area.
Prevent XSS in PHP by escaping output with htmlspecialchars(ENT_QUOTES, UTF-8): reflected XSS demo, sticky forms, attributes, and the cases it does not cover.
A complete JSON REST API in plain PHP 8.4: front controller, router, PDO and SQLite, validation with 422 errors, Bearer token auth and CORS. Every request tested, with real responses.
Hash passwords in PHP with password_hash(), check them with password_verify(), and build a PDO register and login that upgrades old hashes. Real output.
A simple PHP math captcha in two functions: store the answer in the session, check it once with ctype_digit and ===, then add a honeypot and time check.
How I send contact form emails with PHP's built-in mail(): a fixed recipient, Reply-To, header injection checks, a UTF-8 subject and a fake sendmail.
How to validate and sanitize PHP form input: trim, filter_var, mb_strlen and allow-lists, then escape output with htmlspecialchars, add CSRF and redirect.
0%