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.
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.
Step by step: a Gemini key from Google AI Studio in .env.local, a server-only helper, a Next.js route handler, Vercel environment variables and a leak test.
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%