What are the potential risks of exposing PHP script content to users in the browser and how can this be mitigated?

Exposing PHP script content to users in the browser can pose a security risk as it may reveal sensitive information such as database credentials or server paths. To mitigate this risk, PHP scripts should never be directly accessible by users and should be executed on the server side only.

<?php
// This code snippet shows how to prevent direct access to PHP scripts
if(!defined('MY_APP')) {
    die('Direct access not allowed');
}

// Rest of the PHP script here