What are the potential security risks of storing login credentials in a PHP script?

Storing login credentials in a PHP script poses a significant security risk because if an attacker gains access to the script, they can easily retrieve the credentials. To mitigate this risk, it is recommended to store the credentials in a separate configuration file outside of the web root directory.

// config.php
<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'username');
define('DB_PASS', 'password');
define('DB_NAME', 'database');
?>

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

// Use the defined constants for database connection
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
?>