What are some potential security risks associated with viewing the source code of a PHP page online?

One potential security risk associated with viewing the source code of a PHP page online is exposing sensitive information such as database credentials, API keys, or other confidential data. To mitigate this risk, it is important to ensure that sensitive information is not hard-coded directly into the source code. Instead, consider storing sensitive data in environment variables or configuration files that are not accessible to the public.

// Example of storing sensitive information in environment variables
$db_host = getenv('DB_HOST');
$db_username = getenv('DB_USERNAME');
$db_password = getenv('DB_PASSWORD');
$db_name = getenv('DB_NAME');

// Connect to the database using the environment variables
$conn = new mysqli($db_host, $db_username, $db_password, $db_name);