What are the advantages and disadvantages of using a separate configuration file for storing sensitive data like passwords in PHP?
Using a separate configuration file for storing sensitive data like passwords in PHP is advantageous because it helps in separating configuration settings from code, making it easier to manage and update sensitive information without modifying the code. However, if the configuration file is not properly secured, it can still be vulnerable to unauthorized access. It is important to ensure that the configuration file is stored outside the web root directory and is properly encrypted to mitigate security risks.
// config.php
<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'username');
define('DB_PASS', 'password');
define('DB_NAME', 'database_name');
```
```php
// index.php
<?php
require_once 'config.php';
// Connect to the database using the sensitive data from the config file
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
// Rest of the code