What are the potential security risks of storing the username and password directly in a PHP file?

Storing the username and password directly in a PHP file poses a significant security risk because if an attacker gains access to the file, they will have access to sensitive login information. A better approach is to store the credentials in a separate configuration file outside of the web root directory, and then include that file in the PHP script when needed.

// config.php
<?php
define('DB_USERNAME', 'your_username');
define('DB_PASSWORD', 'your_password');
?>

// index.php
<?php
require_once('config.php');

// Use DB_USERNAME and DB_PASSWORD variables in your code
?>