Apply production-grade security headers with one line. Zero dependencies, works on any PHP 8+ shared host.
- Sensible default CSP, HSTS, X-Frame-Options, Referrer-Policy, Permissions-Policy
- Easy per-route overrides
- Supports nonce generation for inline scripts
- Tested on Apache, Nginx, LiteSpeed
composer require yourname/php-secure-headersOr drop SecureHeaders.php into your project.
require 'SecureHeaders.php';
$headers = new SecureHeaders();
$headers->send(); // default secure set
// With nonce for a script
$nonce = $headers->nonce();
$headers->send();Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-abc123'
Strict-Transport-Security: max-age=31536000; includeSubDomains
...
- Add reporting endpoint helper
- CLI validator for header syntax
PRs welcome. Keep changes under 100 lines.