Skip to content
PHP Logo

How can PHP developers ensure that sensitive information, such as usernames and passwords, are not exposed when accessing protected files?

PHP developers can ensure that sensitive information, such as usernames and passwords, are not exposed when accessing protected files by using PHP's built-in functions for handling file operations securely. One way to achieve this is by storing sensitive information in a separate configuration file outside of the web root directory and using PHP's require function to include it in the main application file. This way, the sensitive information is kept secure and not directly accessible to users.

php
<?php

// config.php
return [
    'username' => 'my_username',
    'password' => 'my_password'
];

// index.php
$config = require 'config.php';

echo $config['username'];
echo $config['password'];

?>