What are common issues when using shell_exec in PHP?

Common issues when using shell_exec in PHP include security vulnerabilities due to command injection attacks and potential performance issues. To mitigate these risks, it is recommended to validate and sanitize user input before passing it to shell_exec, and to use escapeshellarg() or escapeshellcmd() to escape any user input that is used in the command.

$user_input = $_POST['user_input']; // Assuming user input is coming from a form

// Validate and sanitize user input
$validated_input = filter_var($user_input, FILTER_SANITIZE_STRING);

// Escape user input before passing it to shell_exec
$escaped_input = escapeshellarg($validated_input);

$output = shell_exec("ls " . $escaped_input);
echo $output;