What measures can be taken to prevent unauthorized access to sensitive data stored in PHP files on a server?

To prevent unauthorized access to sensitive data stored in PHP files on a server, one measure is to move the sensitive data to a separate configuration file outside of the web root directory. This way, the data cannot be accessed directly through the browser. Additionally, you can restrict access to the sensitive files using server-side configurations like .htaccess or by implementing authentication mechanisms.

// Example of moving sensitive data to a separate configuration file
// config.php
<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'username');
define('DB_PASS', 'password');
define('DB_NAME', 'database');
?>

// index.php
<?php
include 'config.php';

// Use the sensitive data here
$connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
?>