How can you securely handle user input from the URL to prevent vulnerabilities in PHP scripts?

To securely handle user input from the URL and prevent vulnerabilities in PHP scripts, you should always sanitize and validate the input before using it in your code. This can help prevent SQL injection, cross-site scripting (XSS), and other security risks. One way to do this is by using functions like htmlentities() or filter_input() to sanitize the input.

// Example of securely handling user input from the URL in PHP

// Get the user input from the URL
$userInput = $_GET['input'];

// Sanitize the input using htmlentities()
$sanitizedInput = htmlentities($userInput);

// Use the sanitized input in your code
echo "User input: " . $sanitizedInput;