What are the potential pitfalls of using $_GET variables directly in a cURL request in PHP, as shown in the provided script?

Using $_GET variables directly in a cURL request without proper validation can expose your application to security vulnerabilities such as SQL injection or cross-site scripting attacks. To mitigate this risk, it is important to sanitize and validate the input before using it in the cURL request.

// Sanitize and validate the $_GET variable before using it in the cURL request
$param_value = isset($_GET['param_name']) ? filter_var($_GET['param_name'], FILTER_SANITIZE_STRING) : '';

// Create cURL request with sanitized input
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/api?param_name=' . urlencode($param_value));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);

if($response === false){
    echo 'cURL error: ' . curl_error($ch);
}

curl_close($ch);