How can string concatenation in PHP impact the execution of commands within the exec() function?

String concatenation in PHP can impact the execution of commands within the exec() function if user input is directly concatenated into the command string without proper validation. This can lead to command injection vulnerabilities where an attacker can manipulate the command being executed. To prevent this, always sanitize and validate user input before concatenating it into the command string.

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

// Sanitize and validate user input before concatenating
$validated_input = escapeshellarg($user_input);

// Execute the command with the validated input
exec("some_command " . $validated_input);