Send basic security headers

A few headers that close common attack routes. Test your Content-Security-Policy before you enforce it, because it blocks inline scripts.

PHP · Send basic security headersIntermediate
header('X-Content-Type-Options: nosniff');
header('X-Frame-Options: SAMEORIGIN');
header('Referrer-Policy: strict-origin-when-cross-origin');
header('Permissions-Policy: camera=(), microphone=(), geolocation=()');
header("Content-Security-Policy: default-src 'self'; img-src 'self' data:; frame-ancestors 'self'");

// Only on HTTPS sites. Tells browsers to always use HTTPS for a year.
if (!empty($_SERVER['HTTPS'])) {
    header('Strict-Transport-Security: max-age=31536000; includeSubDomains');
}
securityheaderscsp