What are some potential pitfalls when including variables from an external file in PHP?

One potential pitfall when including variables from an external file in PHP is the risk of exposing sensitive information, such as database credentials or API keys, if the external file is not properly secured. To solve this issue, it is important to store sensitive information in a separate configuration file with restricted access permissions. Additionally, it is recommended to validate and sanitize any input from external files to prevent security vulnerabilities.

<?php
// config.php
$db_host = "localhost";
$db_user = "username";
$db_pass = "password";
$db_name = "database";

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

// Use the variables from the external file
$connection = new mysqli($db_host, $db_user, $db_pass, $db_name);
if ($connection->connect_error) {
    die("Connection failed: " . $connection->connect_error);
}