Skip to main content
  1. Posts/

Menambahkan Security Headers pada PHP

·1 min·
php php

Panduan ini akan membahas cara menambahkan security header pada PHP. Ini dapat digunakan untuk alternatif dari postingan sebelumnya yaitu menambah security header di cloudflare

Anda dapat menambahkan security header ke situs web menggunakan PHP dengan fungsi header().

<?php
// Add security headers
header('strict-transport-security: max-age=2592000; preload');
header('referrer-policy: same-origin');
header('x-content-type-options: nosniff');
header('x-frame-options: SAMEORIGIN');
header('x-xss-protection: 1; mode=block');
header('content-security-policy: frame-ancestors https://example.com/');

// Add CORS headers (optional)
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: origin, x-requested-with, content-type');
header('Access-Control-Allow-Methods: GET, POST');

// example website content
phpinfo();
?>
Pastikan fungsi header berada dipaling atas atau sebelum website content

Jika ingin menghapus header tertentu dapat menggunakan fungsi header_remove()

header_remove('X-Powered-By');

Related

Install Apache dengan PHP-FPM dan Userdir
·3 mins
apache ubuntu linux php apache
Manage Pages Deployment with Cloudflare API
·2 mins
cloudflare cloudflare
Menambahkan Security Headers di Wordpress
·1 min
wordpress wordpress
Error Bold Themes Nifty Wordpress
·1 min
wordpress wordpress
Membuat Notifikasi Slack untuk AWS CloudWatch
·3 mins
aws aws
Cara Melihat Console dan Log System di AWS EC2
·2 mins
aws aws