How can configuration files like "config.php" be effectively used in PHP web development to store sensitive information?
Sensitive information such as database credentials should not be hard-coded directly into PHP files for security reasons. Instead, a common practice is to store this information in a separate configuration file like "config.php" and then include this file in the necessary scripts. This way, sensitive information is kept separate from the main codebase and can be easily updated without affecting the rest of the application.
// config.php
<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'username');
define('DB_PASS', 'password');
define('DB_NAME', 'database_name');
?>
// index.php
<?php
require_once 'config.php';
$connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
// Rest of the code
?>