Skip to content
PHP Logo

How can config.php be protected to prevent unauthorized access to sensitive information in a PHP application?

To protect config.php from unauthorized access, it should be placed outside the web root directory. This way, it cannot be accessed directly through a URL. Additionally, you can use file permissions to restrict access to the file and encrypt sensitive information stored in the config file.

php
<?php
// Place config.php outside the web root directory
// Restrict access to the file using file permissions
// Encrypt sensitive information stored in the config file

// Example code to include config.php
require_once('/path/to/config.php');