What potential security risks are associated with using shell commands in PHP to retrieve system information?

Using shell commands in PHP to retrieve system information can expose your application to security risks such as command injection attacks. To mitigate this risk, you should always sanitize user input and use functions like escapeshellarg() to escape any user-provided arguments passed to shell commands.

$user_input = $_GET['input']; // Assuming user input is being used
$escaped_input = escapeshellarg($user_input);
$output = shell_exec("some_command " . $escaped_input);
echo $output;