What are the best practices for handling sensitive information, such as passwords, in PHP files?
Sensitive information, such as passwords, should never be hardcoded directly into PHP files as it poses a security risk. Instead, it is best practice to store this information in a separate configuration file outside of the web root directory and include it in your PHP files when needed.
// 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');
// Use the sensitive information as needed
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
?>