What are the potential risks of allowing direct access to PHP files that are meant to be included?

Allowing direct access to PHP files that are meant to be included can pose a security risk as it exposes sensitive code and data to potential attackers. To prevent this, it's important to check if the file is being accessed directly and redirect or stop the execution if it is.

if(basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"])){
    header("HTTP/1.0 403 Forbidden");
    exit("Direct access not allowed");
}