What best practices should be followed when including sensitive information in PHP scripts, such as login credentials?

Sensitive information, such as login credentials, should never be hard-coded directly into PHP scripts as it poses a security risk. Instead, it is recommended to store this information in a separate configuration file outside of the web root directory. This way, even if someone gains access to your PHP files, they won't be able to see the sensitive information.

// config.php
define('DB_HOST', 'localhost');
define('DB_USER', 'username');
define('DB_PASS', 'password');
define('DB_NAME', 'database_name');

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

// Use the defined constants in your PHP script
$connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);