What are the best practices for preventing manual execution of a PHP script from outside sources?

To prevent manual execution of a PHP script from outside sources, you can use a simple check to verify if the script is being accessed directly or included in another script. One common method is to check if a specific constant or variable is defined in the script, and if not, exit the script to prevent manual execution.

<?php

// Check if a specific constant is defined
if(!defined('MY_SCRIPT_CONSTANT')){
    exit('Direct script access not allowed');
}

// Rest of the script goes here