What are the potential pitfalls of not properly handling URL parameters in PHP?

If URL parameters are not properly handled in PHP, it can lead to security vulnerabilities such as SQL injection or cross-site scripting attacks. To mitigate these risks, it is important to sanitize and validate all incoming URL parameters before using them in database queries or displaying them on the webpage.

// Example of sanitizing and validating URL parameters in PHP
$user_id = isset($_GET['user_id']) ? filter_var($_GET['user_id'], FILTER_SANITIZE_NUMBER_INT) : null;

if ($user_id) {
    // Use the sanitized user_id in your code
    // For example, perform a database query using prepared statements
}