How can you ensure that form input values are securely passed to URLs in PHP?

To ensure that form input values are securely passed to URLs in PHP, you should always sanitize and validate user input before including it in URLs to prevent security vulnerabilities such as SQL injection or cross-site scripting attacks. One way to achieve this is by using PHP's built-in `filter_var()` function with the `FILTER_SANITIZE_URL` filter to clean the input data.

// Sanitize and validate form input before passing it to a URL
$inputValue = $_POST['input_field'] ?? ''; // Get input value from form
$sanitizedValue = filter_var($inputValue, FILTER_SANITIZE_URL); // Sanitize input value

// Use the sanitized value in the URL
$url = 'https://example.com/?param=' . urlencode($sanitizedValue);