What are the potential consequences of using the exec() function in PHP for executing external commands?
Using the exec() function in PHP to execute external commands can pose security risks if not handled properly. It opens up the possibility of command injection attacks where malicious commands can be injected and executed on the server. To mitigate this risk, it is important to sanitize and validate any user input before passing it to the exec() function.
$user_input = $_POST['input']; // Assuming input is coming from a form field
// Sanitize and validate user input before passing it to exec()
$clean_input = escapeshellarg($user_input);
// Execute the command safely
exec("command $clean_input");