What are the potential security risks of storing sensitive information like server credentials in PHP files?

Storing sensitive information like server credentials in PHP files can pose a security risk if the files are accessible to unauthorized users. To mitigate this risk, it is recommended to store sensitive information in environment variables or use a secure key management system. This helps prevent the credentials from being exposed in case of a security breach or unauthorized access.

// Storing sensitive information in environment variables
$servername = getenv('DB_SERVERNAME');
$username = getenv('DB_USERNAME');
$password = getenv('DB_PASSWORD');
$dbname = getenv('DB_NAME');

// Using the credentials in your PHP code
$connection = new mysqli($servername, $username, $password, $dbname);