My site is plain PHP on shared hosting. No framework, no middleware, and no server config I can touch beyond one file: .htaccess . That sounds limiting, but the cheapest security hardening I do on any PHP site lives in three lines of that file.
The trick is mod_headers , which most shared hosts, including mine, have switched on already. It lets me attach response headers from .htaccess , and the browser does the rest. If your host has it off, these lines silently do nothing β which is why I check with curl -I after every deploy instead of assuming.
1. X-Content-Type-Options: nosniff
Header set X - Content - Type - Options "nosniff"
Enter fullscreen mode
Exit fullscreen mode
Browsers like to guess. If a file arrives with a vague or wrong content type, the browser sniffs the bytes and decides for itself what it is looking at. That guessing is how a file that should be treated as inert data gets executed as something else.
My site proxies video files, so this one matters more than most.β¦