What are the best practices for securely accessing and executing external code in PHP applications?
When accessing and executing external code in PHP applications, it is important to follow best practices to ensure security. One way to do this is by using functions like `escapeshellcmd()` and `escapeshellarg()` to sanitize input and prevent command injection attacks. Additionally, it is recommended to limit the permissions of the user executing the external code and validate any input received from external sources.
// Sanitize input using escapeshellarg()
$externalInput = escapeshellarg($_GET['input']);
// Execute external code with limited permissions
exec("external_script.sh $externalInput", $output);