What are the common pitfalls to avoid when using PHP to gather system information like date, time, and user agent?

One common pitfall is not properly sanitizing user input when using PHP to gather system information. This can lead to security vulnerabilities such as SQL injection attacks. To avoid this, always validate and sanitize user input before using it in PHP functions.

$user_agent = filter_input(INPUT_SERVER, 'HTTP_USER_AGENT', FILTER_SANITIZE_STRING);
$date = date('Y-m-d H:i:s');
$time = date('H:i:s');