What potential issues can arise when using the exec() function in PHP?
One potential issue with using the exec() function in PHP is the risk of command injection, where an attacker could manipulate input to execute arbitrary commands on the server. To mitigate this risk, it is important to sanitize user input and validate any commands being passed to exec(). Additionally, using escapeshellarg() or escapeshellcmd() to escape user input can help prevent command injection attacks.
$user_input = $_POST['user_input'];
$command = 'ls ' . escapeshellarg($user_input);
exec($command, $output);