How can access credentials be protected in PHP files to prevent unauthorized access?

To protect access credentials in PHP files and prevent unauthorized access, it is recommended to store sensitive information such as database credentials in a separate configuration file outside of the web root directory. This way, the credentials are not directly accessible via the browser and are only included in the PHP files that need them.

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

```php
// index.php
require_once('config.php');

// Use the defined constants to establish a database connection
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);