What are the best practices for including configuration files in PHP scripts?
When including configuration files in PHP scripts, it is important to store sensitive information such as database credentials securely. One common best practice is to store configuration settings in a separate file outside of the web root directory to prevent unauthorized access. Additionally, using constants to define configuration values can help ensure consistency and prevent accidental changes.
// config.php
define('DB_HOST', 'localhost');
define('DB_USER', 'username');
define('DB_PASS', 'password');
define('DB_NAME', 'database_name');
```
```php
// index.php
require_once('/path/to/config.php');
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
// Use $mysqli object for database operations